added unapprove
Deploy / deploy (push) Successful in 2m37s

This commit is contained in:
twotalesanimation
2026-06-11 15:19:12 +02:00
parent 7b9bbbec16
commit b640fa472c
5 changed files with 361 additions and 2 deletions
+37
View File
@@ -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.