fix: align ticket timers to server clock
This commit is contained in:
parent
3b5676ed35
commit
090ebb9607
7 changed files with 162 additions and 17 deletions
|
|
@ -461,6 +461,7 @@ export const list = query({
|
|||
subcategorySummary = { id: subcategory._id, name: subcategory.name };
|
||||
}
|
||||
}
|
||||
const serverNow = Date.now()
|
||||
return {
|
||||
id: t._id,
|
||||
reference: t.reference,
|
||||
|
|
@ -497,6 +498,7 @@ export const list = query({
|
|||
totalWorkedMs: t.totalWorkedMs ?? 0,
|
||||
internalWorkedMs: t.internalWorkedMs ?? 0,
|
||||
externalWorkedMs: t.externalWorkedMs ?? 0,
|
||||
serverNow,
|
||||
activeSession: activeSession
|
||||
? {
|
||||
id: activeSession._id,
|
||||
|
|
@ -546,6 +548,7 @@ export const getById = query({
|
|||
visibleComments.map((comment) => `${comment.createdAt}:${comment.authorId}`)
|
||||
)
|
||||
const visibleCommentTimestamps = new Set(visibleComments.map((comment) => comment.createdAt))
|
||||
const serverNow = Date.now()
|
||||
|
||||
let timelineRecords = await ctx.db
|
||||
.query("ticketEvents")
|
||||
|
|
@ -678,6 +681,7 @@ export const getById = query({
|
|||
totalWorkedMs: t.totalWorkedMs ?? 0,
|
||||
internalWorkedMs: t.internalWorkedMs ?? 0,
|
||||
externalWorkedMs: t.externalWorkedMs ?? 0,
|
||||
serverNow,
|
||||
activeSession: activeSession
|
||||
? {
|
||||
id: activeSession._id,
|
||||
|
|
@ -1255,11 +1259,13 @@ export const workSummary = query({
|
|||
await requireStaff(ctx, viewerId, ticket.tenantId)
|
||||
|
||||
const activeSession = ticket.activeSessionId ? await ctx.db.get(ticket.activeSessionId) : null
|
||||
const serverNow = Date.now()
|
||||
return {
|
||||
ticketId,
|
||||
totalWorkedMs: ticket.totalWorkedMs ?? 0,
|
||||
internalWorkedMs: ticket.internalWorkedMs ?? 0,
|
||||
externalWorkedMs: ticket.externalWorkedMs ?? 0,
|
||||
serverNow,
|
||||
activeSession: activeSession
|
||||
? {
|
||||
id: activeSession._id,
|
||||
|
|
@ -1303,16 +1309,22 @@ export const startWork = mutation({
|
|||
const viewer = await requireTicketStaff(ctx, actorId, ticketDoc)
|
||||
const isAdmin = viewer.role === "ADMIN"
|
||||
const currentAssigneeId = ticketDoc.assigneeId ?? null
|
||||
const now = Date.now()
|
||||
|
||||
if (currentAssigneeId && currentAssigneeId !== actorId && !isAdmin) {
|
||||
throw new ConvexError("Somente o responsável atual pode iniciar este chamado")
|
||||
}
|
||||
|
||||
if (ticketDoc.activeSessionId) {
|
||||
return { status: "already_started", sessionId: ticketDoc.activeSessionId }
|
||||
const session = await ctx.db.get(ticketDoc.activeSessionId)
|
||||
return {
|
||||
status: "already_started",
|
||||
sessionId: ticketDoc.activeSessionId,
|
||||
startedAt: session?.startedAt ?? now,
|
||||
serverNow: now,
|
||||
}
|
||||
}
|
||||
|
||||
const now = Date.now()
|
||||
let assigneePatched = false
|
||||
|
||||
if (!currentAssigneeId) {
|
||||
|
|
@ -1356,7 +1368,7 @@ export const startWork = mutation({
|
|||
createdAt: now,
|
||||
})
|
||||
|
||||
return { status: "started", sessionId, startedAt: now }
|
||||
return { status: "started", sessionId, startedAt: now, serverNow: now }
|
||||
},
|
||||
})
|
||||
|
||||
|
|
@ -1439,6 +1451,7 @@ export const pauseWork = mutation({
|
|||
durationMs,
|
||||
pauseReason: reason,
|
||||
pauseNote: note ?? "",
|
||||
serverNow: now,
|
||||
}
|
||||
},
|
||||
})
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue