Ajusta timeline, comentários internos e contadores de trabalho

This commit is contained in:
Esdras Renan 2025-10-07 22:12:18 -03:00
parent ee18619519
commit ef25cbe799
7 changed files with 212 additions and 69 deletions

View file

@ -413,6 +413,10 @@ export const getById = query({
.query("ticketComments")
.withIndex("by_ticket", (q) => q.eq("ticketId", id))
.collect();
const canViewInternalComments = role === "ADMIN" || role === "AGENT";
const visibleComments = canViewInternalComments
? comments
: comments.filter((comment) => comment.visibility !== "INTERNAL");
const timeline = await ctx.db
.query("ticketEvents")
.withIndex("by_ticket", (q) => q.eq("ticketId", id))
@ -423,7 +427,7 @@ export const getById = query({
);
const commentsHydrated = await Promise.all(
comments.map(async (c) => {
visibleComments.map(async (c) => {
const author = (await ctx.db.get(c.authorId)) as Doc<"users"> | null;
const attachments = await Promise.all(
(c.attachments ?? []).map(async (att) => ({
@ -707,6 +711,10 @@ export const addComment = mutation({
throw new ConvexError("Gestores só podem registrar comentários públicos")
}
}
const canUseInternalComments = normalizedRole === "ADMIN" || normalizedRole === "AGENT"
if (args.visibility === "INTERNAL" && !canUseInternalComments) {
throw new ConvexError("Apenas administradores e agentes podem registrar comentários internos")
}
if (ticketDoc.requesterId === args.authorId) {
// requester commenting: managers restricted to PUBLIC (handled above);