refactor: enhance email scheduling functionality and improve error handling

- Added a new mutation to cancel scheduled emails, ensuring only pending emails can be canceled.
- Updated the current user query to use type casting for better type safety.
- Improved the handling of email status queries to skip execution when no email IDs are present.
- Refactored error checking for template queries to streamline the code and remove unused variables.
- Enhanced user feedback for authentication requirements when sending notifications.
This commit is contained in:
2025-11-20 14:13:05 -03:00
parent 9451e69d68
commit 51e2efa07e
2 changed files with 70 additions and 46 deletions

View File

@@ -162,6 +162,29 @@ export const enfileirarEmail = mutation({
},
});
/**
* Cancelar agendamento de email
*/
export const cancelarAgendamentoEmail = mutation({
args: {
emailId: v.id("notificacoesEmail"),
},
handler: async (ctx, args) => {
const email = await ctx.db.get(args.emailId);
if (!email) {
return { sucesso: false, erro: "Email não encontrado" };
}
if (email.status !== "pendente") {
return { sucesso: false, erro: "Apenas emails pendentes podem ser cancelados" };
}
// Remove o email da fila
await ctx.db.delete(args.emailId);
return { sucesso: true };
},
});
/**
* Enviar email usando template
*/