feat: enable ticket comment editing

Co-authored-by: factory-droid[bot] <138933559+factory-droid[bot]@users.noreply.github.com>
This commit is contained in:
esdrasrenan 2025-10-05 02:08:20 -03:00
parent 533d9ca856
commit 07ff117a67
5 changed files with 340 additions and 56 deletions

View file

@ -405,6 +405,45 @@ export const addComment = mutation({
},
});
export const updateComment = mutation({
args: {
ticketId: v.id("tickets"),
commentId: v.id("ticketComments"),
actorId: v.id("users"),
body: v.string(),
},
handler: async (ctx, { ticketId, commentId, actorId, body }) => {
const comment = await ctx.db.get(commentId);
if (!comment || comment.ticketId !== ticketId) {
throw new ConvexError("Comentário não encontrado");
}
if (comment.authorId !== actorId) {
throw new ConvexError("Você não tem permissão para editar este comentário");
}
const now = Date.now();
await ctx.db.patch(commentId, {
body,
updatedAt: now,
});
const actor = (await ctx.db.get(actorId)) as Doc<"users"> | null;
await ctx.db.insert("ticketEvents", {
ticketId,
type: "COMMENT_EDITED",
payload: {
commentId,
actorId,
actorName: actor?.name,
actorAvatar: actor?.avatarUrl,
},
createdAt: now,
});
await ctx.db.patch(ticketId, { updatedAt: now });
},
});
export const removeCommentAttachment = mutation({
args: {
ticketId: v.id("tickets"),