feat: implement homologation deletion and detail viewing features

- Added functionality to delete homologations, restricted to users with managerial permissions.
- Introduced modals for viewing details of homologations and confirming deletions, enhancing user interaction.
- Updated the backend to support homologation deletion, including necessary permission checks and data integrity management.
- Enhanced the UI to display alerts for unassociated employees and active dispensas during point registration, improving user feedback and error handling.
This commit is contained in:
2025-11-20 07:01:33 -03:00
parent 57c37fedef
commit 8ea5c0316b
3 changed files with 409 additions and 3 deletions

View File

@@ -1052,6 +1052,48 @@ export const listarHomologacoes = query({
},
});
/**
* Exclui uma homologação (apenas para gestores)
*/
export const excluirHomologacao = mutation({
args: {
homologacaoId: v.id('homologacoesPonto'),
},
handler: async (ctx, args) => {
const usuario = await getCurrentUserFunction(ctx);
if (!usuario) {
throw new Error('Usuário não autenticado');
}
const homologacao = await ctx.db.get(args.homologacaoId);
if (!homologacao) {
throw new Error('Homologação não encontrada');
}
// Verificar se é gestor do funcionário
const isGestor = await verificarGestorDoFuncionario(ctx, usuario._id, homologacao.funcionarioId);
if (!isGestor && homologacao.gestorId !== usuario._id) {
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
if (homologacao.registroId) {
const registro = await ctx.db.get(homologacao.registroId);
if (registro && registro.homologacaoId === args.homologacaoId) {
await ctx.db.patch(homologacao.registroId, {
homologacaoId: undefined,
editadoPorGestor: false,
});
}
}
// Excluir homologação
await ctx.db.delete(args.homologacaoId);
return { success: true };
},
});
/**
* Obtém opções de motivos de atestados/declarações
*/