From 9f14ae59ffdc5ee5dd0f9562d0e942622b86d644 Mon Sep 17 00:00:00 2001 From: Anthony Janin Date: Tue, 5 Aug 2025 14:52:29 +0200 Subject: [PATCH] Fix some issues --- src/server.js | 57 +++++++++------------------------------------------ 1 file changed, 10 insertions(+), 47 deletions(-) diff --git a/src/server.js b/src/server.js index a49a455..6abc018 100644 --- a/src/server.js +++ b/src/server.js @@ -665,69 +665,32 @@ app.post('/api/subscribe-to-list', validateEmail, async (req, res) => { } }); -app.post('/api/:uid/send_reminder', validateEmail, async (req, res) => { - const { email, documentsUid } = req.body; +app.post('/api/send_reminder', async (req, res) => { + const { office, customer } = req.body; try { - const uid = req.params["uid"]; - if (!uid) { - //this.httpBadRequest(response, "No uid provided"); - return; - } - - if (!documentsUid || !Array.isArray(documentsUid)) { - //this.httpBadRequest(response, "Invalid or missing documents"); - return; - } - - /* - const documentEntities: Documents[] = []; - //For each document uid, use DocumentsService.getByUid to get the document entity and add it to the documents array - for (const documentUid of documentsUid) { - const documentEntity = await this.documentsService.getByUid(documentUid, { document_type: true, folder: true }); - - if (!documentEntity) { - this.httpBadRequest(response, "Document not found"); - return; - } - documentEntities.push(documentEntity); - } - - const customerEntity = await this.customersService.getByUid(uid, { contact: true, office: true }); - - if (!customerEntity) { - this.httpNotFoundRequest(response, "customer not found"); - return; - } - - //Hydrate ressource with prisma entity - const customer = Customer.hydrate < Customer > (customerEntity, { strategy: "excludeAll" }); - - // Call service to send reminder with documents - await this.customersService.sendDocumentsReminder(customer, documentEntities); - */ + const to = customer.contact.email; const templateVariables = { - first_name: 'firstName' || '', - last_name: 'lastName' || '', - office_name: 'officeName' || '', + office_name: office.name, + last_name: customer.contact.last_name || '', + first_name: customer.contact.first_name || '', link: `${process.env.APP_HOST}` }; - const result = await EmailService.sendTransactionalEmail( - email, + await EmailService.sendTransactionalEmail( + to, ETemplates.DOCUMENT_REMINDER, - 'Votre notaire vous envoie un message', + 'Vous avez des documents à déposer pour votre dossier.', templateVariables ); - console.log(result); res.json({ success: true, message: 'Email envoyé avec succès' }); } catch (error) { - console.log(error); + console.error(error); return; } });