Added delete version
Deploy / deploy (push) Successful in 2m28s

This commit is contained in:
twotalesanimation
2026-05-20 21:53:18 +02:00
parent 05475a6c19
commit e4eb8fb3a9
3 changed files with 102 additions and 0 deletions
+42
View File
@@ -165,6 +165,48 @@ export async function shareVersionWithClient(versionId: string) {
return { success: true };
}
export async function deleteVersion(versionId: 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 version = await db.version.findUnique({
where: { id: versionId },
select: {
id: true,
isLatest: true,
taskId: true,
task: { select: { projectId: true, shotId: true } },
},
});
if (!version) throw new Error("Version not found");
// If this was the latest version, promote the next most recent one
if (version.isLatest && version.taskId) {
const next = await db.version.findFirst({
where: { taskId: version.taskId, id: { not: versionId } },
orderBy: { versionNumber: "desc" },
select: { id: true },
});
if (next) {
await db.version.update({ where: { id: next.id }, data: { isLatest: true } });
}
}
await db.version.delete({ where: { id: versionId } });
const projectId = version.task?.projectId;
const shotId = version.task?.shotId;
if (shotId) await recalcShotStatus(shotId).catch(() => {});
if (projectId) revalidatePath(`/projects/${projectId}`);
if (version.taskId) revalidatePath(`/tasks/${version.taskId}`);
if (shotId && projectId) revalidatePath(`/projects/${projectId}/shots/${shotId}`);
return { success: true };
}
export async function getVersionById(versionId: string) {
const session = await auth();
if (!session?.user) throw new Error("Unauthorized");