Ajustes final etapa1 #71
@@ -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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user