@@ -958,6 +958,7 @@ export interface SimpleCsvRow {
|
||||
seqTimecodeStart: string;
|
||||
seqTimecodeEnd: string;
|
||||
description: string;
|
||||
group: string;
|
||||
action: "create" | "update" | "skip";
|
||||
}
|
||||
|
||||
@@ -985,12 +986,20 @@ export async function importShotsFromSimpleCsv(
|
||||
});
|
||||
|
||||
if (existing) {
|
||||
const shotGroupId = row.group?.trim()
|
||||
? (await db.shotGroup.upsert({
|
||||
where: { projectId_name: { projectId, name: row.group.trim() } },
|
||||
create: { projectId, name: row.group.trim() },
|
||||
update: {},
|
||||
})).id
|
||||
: undefined;
|
||||
await db.shot.update({
|
||||
where: { id: existing.id },
|
||||
data: {
|
||||
description: row.description || null,
|
||||
seqTimecodeStart: row.seqTimecodeStart || null,
|
||||
seqTimecodeEnd: row.seqTimecodeEnd || null,
|
||||
...(shotGroupId ? { shotGroupId } : {}),
|
||||
},
|
||||
});
|
||||
updated.push(row.shotCode);
|
||||
@@ -1004,6 +1013,13 @@ export async function importShotsFromSimpleCsv(
|
||||
select: { shotNumber: true },
|
||||
});
|
||||
const shotNumber = (maxNum?.shotNumber ?? 0) + 10;
|
||||
const shotGroupId = row.group?.trim()
|
||||
? (await db.shotGroup.upsert({
|
||||
where: { projectId_name: { projectId, name: row.group.trim() } },
|
||||
create: { projectId, name: row.group.trim() },
|
||||
update: {},
|
||||
})).id
|
||||
: undefined;
|
||||
|
||||
await db.shot.create({
|
||||
data: {
|
||||
@@ -1015,6 +1031,7 @@ export async function importShotsFromSimpleCsv(
|
||||
description: row.description || null,
|
||||
seqTimecodeStart: row.seqTimecodeStart || null,
|
||||
seqTimecodeEnd: row.seqTimecodeEnd || null,
|
||||
shotGroupId,
|
||||
},
|
||||
});
|
||||
created.push(row.shotCode);
|
||||
@@ -1031,6 +1048,57 @@ export async function importShotsFromSimpleCsv(
|
||||
return { created, updated, skipped, errors };
|
||||
}
|
||||
|
||||
// ── Group Assignment ──────────────────────────────────────────────────────────────────
|
||||
|
||||
export interface GroupAssignRow {
|
||||
shotCode: string;
|
||||
groupName: string;
|
||||
exists: boolean;
|
||||
}
|
||||
|
||||
export async function assignShotGroups(
|
||||
projectId: string,
|
||||
rows: GroupAssignRow[]
|
||||
): Promise<{ assigned: string[]; skipped: string[]; errors: string[] }> {
|
||||
const session = await auth();
|
||||
if (!session?.user) throw new Error("Unauthorized");
|
||||
if (!["ADMIN", "PRODUCER", "SUPERVISOR"].includes(session.user.role)) {
|
||||
throw new Error("Insufficient permissions");
|
||||
}
|
||||
|
||||
const assigned: string[] = [];
|
||||
const skipped: string[] = [];
|
||||
const errors: string[] = [];
|
||||
|
||||
for (const row of rows) {
|
||||
if (!row.exists) { skipped.push(row.shotCode); continue; }
|
||||
try {
|
||||
const shot = await db.shot.findFirst({
|
||||
where: { projectId, shotCode: row.shotCode },
|
||||
select: { id: true },
|
||||
});
|
||||
if (!shot) { skipped.push(row.shotCode); continue; }
|
||||
|
||||
const group = await db.shotGroup.upsert({
|
||||
where: { projectId_name: { projectId, name: row.groupName.trim() } },
|
||||
create: { projectId, name: row.groupName.trim() },
|
||||
update: {},
|
||||
});
|
||||
|
||||
await db.shot.update({
|
||||
where: { id: shot.id },
|
||||
data: { shotGroupId: group.id },
|
||||
});
|
||||
assigned.push(row.shotCode);
|
||||
} catch (e) {
|
||||
errors.push(`${row.shotCode}: ${e instanceof Error ? e.message : "Unknown error"}`);
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath(`/projects/${projectId}`);
|
||||
return { assigned, skipped, errors };
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal: handle client requesting changes on a shot.
|
||||
* Resets shotApprovalStatus = PENDING, sharedWithClient = false.
|
||||
|
||||
Reference in New Issue
Block a user