@@ -744,6 +744,43 @@ export async function clientApproveShot(shotId: string) {
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin/Producer/Supervisor: undo a client approval on a shot.
|
||||
* Resets shotApprovalStatus from CLIENT_APPROVED → INTERNALLY_APPROVED.
|
||||
* Shot status reverts to CLIENT_REVIEW (if still shared) or READY_FOR_CLIENT.
|
||||
*/
|
||||
export async function unapproveShot(shotId: 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 shot = await db.shot.findUnique({
|
||||
where: { id: shotId },
|
||||
select: { projectId: true, shotApprovalStatus: true, sharedWithClient: true },
|
||||
});
|
||||
if (!shot) throw new Error("Shot not found");
|
||||
if (shot.shotApprovalStatus !== "CLIENT_APPROVED") {
|
||||
throw new Error("Shot is not client-approved");
|
||||
}
|
||||
|
||||
const newStatus = shot.sharedWithClient ? "CLIENT_REVIEW" : "READY_FOR_CLIENT";
|
||||
|
||||
await db.shot.update({
|
||||
where: { id: shotId },
|
||||
data: {
|
||||
shotApprovalStatus: "INTERNALLY_APPROVED",
|
||||
status: newStatus,
|
||||
},
|
||||
});
|
||||
|
||||
revalidatePath(`/projects/${shot.projectId}`);
|
||||
revalidatePath(`/projects/${shot.projectId}/shots/${shotId}`);
|
||||
revalidatePath(`/shot-status`);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
/**
|
||||
* Internal: handle client requesting changes on a shot.
|
||||
* Resets shotApprovalStatus = PENDING, sharedWithClient = false.
|
||||
|
||||
Reference in New Issue
Block a user