feat(tickets): Play e Chat atribuem responsavel automaticamente

- Botao Play habilitado mesmo sem responsavel
- Ao clicar Play sem responsavel, atribui usuario logado automaticamente
- Ao iniciar chat ao vivo sem responsavel, atribui usuario logado
- Adiciona mutation fixLegacySessions para corrigir sessoes antigas

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
rever-tecnologia 2025-12-15 16:10:13 -03:00
parent 3bfc5793f1
commit 98b23af4b2
3 changed files with 105 additions and 15 deletions

View file

@ -896,6 +896,47 @@ export const autoEndInactiveSessions = mutation({
},
})
// Mutation para corrigir sessoes antigas sem campos obrigatorios
export const fixLegacySessions = mutation({
args: {},
handler: async (ctx) => {
const now = Date.now()
// Buscar sessoes ativas que podem ter campos faltando
const activeSessions = await ctx.db
.query("liveChatSessions")
.withIndex("by_status_lastActivity", (q) => q.eq("status", "ACTIVE"))
.take(100)
let fixed = 0
let ended = 0
for (const session of activeSessions) {
// Se sessao nao tem lastAgentMessageAt, adiciona o valor de startedAt
if (session.lastAgentMessageAt === undefined) {
// Sessao muito antiga (mais de 24h) - encerrar
if (now - session.startedAt > 24 * 60 * 60 * 1000) {
await ctx.db.patch(session._id, {
status: "ENDED",
endedAt: now,
lastAgentMessageAt: session.lastActivityAt ?? session.startedAt,
})
ended++
} else {
// Sessao recente - apenas corrigir o campo
await ctx.db.patch(session._id, {
lastAgentMessageAt: session.lastActivityAt ?? session.startedAt,
})
fixed++
}
}
}
console.log(`fixLegacySessions: fixed=${fixed}, ended=${ended}`)
return { fixed, ended, total: activeSessions.length }
},
})
// ============================================
// UPLOAD DE ARQUIVOS (Maquina/Cliente)
// ============================================