@@ -136,6 +136,25 @@ export async function resolveComment(commentId: string, resolved: boolean) {
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
export async function editComment(commentId: string, newText: string) {
|
||||
const session = await auth();
|
||||
if (!session?.user) throw new Error("Unauthorized");
|
||||
|
||||
const trimmed = newText.trim();
|
||||
if (!trimmed) throw new Error("Comment text cannot be empty");
|
||||
|
||||
const comment = await db.comment.findUnique({ where: { id: commentId } });
|
||||
if (!comment) throw new Error("Comment not found");
|
||||
|
||||
if (comment.authorId !== session.user.id && session.user.role !== "ADMIN") {
|
||||
throw new Error("Unauthorized");
|
||||
}
|
||||
|
||||
await db.comment.update({ where: { id: commentId }, data: { text: trimmed } });
|
||||
revalidatePath(`/review/${comment.versionId}`);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
export async function deleteComment(commentId: string) {
|
||||
const session = await auth();
|
||||
if (!session?.user) throw new Error("Unauthorized");
|
||||
@@ -149,6 +168,14 @@ export async function deleteComment(commentId: string) {
|
||||
}
|
||||
|
||||
await db.comment.delete({ where: { id: commentId } });
|
||||
|
||||
// If this was an annotation companion comment, also delete the canvas drawings at that frame
|
||||
if (comment.text.startsWith("✏️ Annotation at frame")) {
|
||||
await db.annotation.deleteMany({
|
||||
where: { versionId: comment.versionId, frameNumber: comment.frameNumber },
|
||||
});
|
||||
}
|
||||
|
||||
revalidatePath(`/review/${comment.versionId}`);
|
||||
return { success: true };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user