feat: restore original values for linked records upon homologation deletion, including recalculation of work hours based on previous time entries, enhancing data integrity and user experience

This commit is contained in:
2025-12-23 22:18:30 -03:00
parent 5369a2ecc9
commit c6a52155ee

View File

@@ -2867,14 +2867,41 @@ export const excluirHomologacao = mutation({
throw new Error('Você não tem permissão para excluir esta homologação'); throw new Error('Você não tem permissão para excluir esta homologação');
} }
// Se a homologação estiver vinculada a um registro, remover a referência // Se a homologação estiver vinculada a um registro, restaurar valores originais
if (homologacao.registroId) { if (homologacao.registroId) {
const registro = await ctx.db.get(homologacao.registroId); const registro = await ctx.db.get(homologacao.registroId);
if (registro && registro.homologacaoId === args.homologacaoId) { if (registro && registro.homologacaoId === args.homologacaoId) {
await ctx.db.patch(homologacao.registroId, { // Restaurar valores originais se existirem
const patchData: {
homologacaoId: undefined;
editadoPorGestor: boolean;
hora?: number;
minuto?: number;
} = {
homologacaoId: undefined, homologacaoId: undefined,
editadoPorGestor: false editadoPorGestor: false
}); };
// Se a homologação tem valores anteriores, restaurar
if (
homologacao.horaAnterior !== undefined &&
homologacao.minutoAnterior !== undefined
) {
patchData.hora = homologacao.horaAnterior;
patchData.minuto = homologacao.minutoAnterior;
}
await ctx.db.patch(homologacao.registroId, patchData);
// Recalcular banco de horas após restaurar valores
const config = await ctx.db
.query('configuracaoPonto')
.withIndex('by_ativo', (q) => q.eq('ativo', true))
.first();
if (config) {
await atualizarBancoHoras(ctx, registro.funcionarioId, registro.data, config);
}
} }
} }