feat: enhance SLA management and authentication handling
- Updated the useConvexWithAuth hook to improve token management and logging for better debugging. - Integrated automatic authentication handling in the central-chamados route, ensuring seamless user experience. - Added a new mutation for migrating old SLA configurations to include a priority field, enhancing data consistency. - Improved the display of SLA configurations in the UI, including detailed views and migration feedback for better user interaction. - Refactored ticket loading logic to enrich ticket data with responsible user names, improving clarity in ticket management.
This commit is contained in:
@@ -328,8 +328,23 @@ export const listarChamadosTI = query({
|
||||
return true;
|
||||
});
|
||||
|
||||
filtrados.sort((a, b) => b.atualizadoEm - a.atualizadoEm);
|
||||
return args.limite ? filtrados.slice(0, args.limite) : filtrados;
|
||||
// Enriquecer tickets com nome do responsável
|
||||
const ticketsEnriquecidos = await Promise.all(
|
||||
filtrados.map(async (ticket) => {
|
||||
let responsavelNome: string | undefined = undefined;
|
||||
if (ticket.responsavelId) {
|
||||
const responsavel = await ctx.db.get(ticket.responsavelId);
|
||||
responsavelNome = responsavel?.nome;
|
||||
}
|
||||
return {
|
||||
...ticket,
|
||||
responsavelNome,
|
||||
};
|
||||
})
|
||||
);
|
||||
|
||||
ticketsEnriquecidos.sort((a, b) => b.atualizadoEm - a.atualizadoEm);
|
||||
return args.limite ? ticketsEnriquecidos.slice(0, args.limite) : ticketsEnriquecidos;
|
||||
},
|
||||
});
|
||||
|
||||
@@ -703,3 +718,40 @@ export const generateUploadUrl = mutation({
|
||||
},
|
||||
});
|
||||
|
||||
/**
|
||||
* Migração: Adiciona o campo 'prioridade' aos SLAs antigos que não possuem
|
||||
* Esta mutation corrige documentos criados antes da migração do schema
|
||||
*/
|
||||
export const migrarSlaConfigs = mutation({
|
||||
args: {},
|
||||
handler: async (ctx) => {
|
||||
const usuario = await assertAuth(ctx);
|
||||
|
||||
// Buscar todos os SLAs
|
||||
const slaConfigs = await ctx.db.query("slaConfigs").collect();
|
||||
|
||||
let migrados = 0;
|
||||
for (const sla of slaConfigs) {
|
||||
// Verificar se o documento não tem o campo 'prioridade'
|
||||
// Usando type assertion para acessar campos não tipados
|
||||
const slaDoc = sla as any;
|
||||
if (!slaDoc.prioridade) {
|
||||
// Adicionar prioridade padrão "media" para SLAs antigos
|
||||
await ctx.db.patch(sla._id, {
|
||||
prioridade: "media" as "baixa" | "media" | "alta" | "critica",
|
||||
atualizadoPor: usuario._id,
|
||||
atualizadoEm: Date.now(),
|
||||
});
|
||||
migrados++;
|
||||
console.log(`✅ SLA migrado: ${sla.nome} (ID: ${sla._id})`);
|
||||
}
|
||||
}
|
||||
|
||||
return {
|
||||
sucesso: true,
|
||||
migrados,
|
||||
total: slaConfigs.length,
|
||||
};
|
||||
},
|
||||
});
|
||||
|
||||
|
||||
@@ -913,11 +913,13 @@ export default defineSchema({
|
||||
slaConfigs: defineTable({
|
||||
nome: v.string(),
|
||||
descricao: v.optional(v.string()),
|
||||
prioridade: v.union(
|
||||
v.literal("baixa"),
|
||||
v.literal("media"),
|
||||
v.literal("alta"),
|
||||
v.literal("critica")
|
||||
prioridade: v.optional(
|
||||
v.union(
|
||||
v.literal("baixa"),
|
||||
v.literal("media"),
|
||||
v.literal("alta"),
|
||||
v.literal("critica")
|
||||
)
|
||||
),
|
||||
tempoRespostaHoras: v.number(),
|
||||
tempoConclusaoHoras: v.number(),
|
||||
|
||||
Reference in New Issue
Block a user