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:
@@ -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
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user