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:
@@ -2867,14 +2867,41 @@ export const excluirHomologacao = mutation({
|
||||
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) {
|
||||
const registro = await ctx.db.get(homologacao.registroId);
|
||||
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,
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user