diff --git a/src/common/emails/EmailBuilder.ts b/src/common/emails/EmailBuilder.ts index c468fe55..8c61d608 100644 --- a/src/common/emails/EmailBuilder.ts +++ b/src/common/emails/EmailBuilder.ts @@ -15,12 +15,19 @@ export default class EmailBuilder{ public async sendDocumentEmails(documentEntity: Documents){ if(documentEntity.document_status !== "ASKED" && documentEntity.document_status !== "REFUSED") return; + let templateName = ETemplates.DOCUMENT_ASKED; + let subject = "Votre notaire vous demande de déposer des pièces pour traiter votre dossier."; + if(documentEntity.document_status === "REFUSED"){ + templateName = ETemplates.DOCUMENT_REFUSED; + subject = "Un ou plusieurs documents ne sont pas validés. Vous avez une nouvelle action à réaliser."; + } + const documentPrisma = await this.documentsService.getByUid(documentEntity.uid, { depositor: {include: {contact: true}}, folder:{include:{ office: true}} }); if(!documentPrisma) throw new Error("Document not found"); const document = Document.hydrate(documentPrisma); //Use mailchimpService.get get if an email was sent to the user in the lst hour - const lastEmail = await this.mailchimpService.get({ where: { to: document.depositor!.contact!.email, sentAt: { gte: new Date(Date.now() - 3600000) } } }); + const lastEmail = await this.mailchimpService.get({ where: { to: document.depositor!.contact!.email, sentAt: { gte: new Date(Date.now() - 3600000) }, templateName: templateName} }); if(lastEmail.length > 0) return; const to = document.depositor!.contact!.email; @@ -31,13 +38,6 @@ export default class EmailBuilder{ link: `${this.variables.APP_HOST}/customer-login` }; - let templateName = ETemplates.DOCUMENT_ASKED; - let subject = "Votre notaire vous demande de déposer des pièces pour traiter votre dossier."; - if(documentEntity.document_status === "REFUSED"){ - templateName = ETemplates.DOCUMENT_REFUSED; - subject = "Un ou plusieurs documents ne sont pas validés. Vous avez une nouvelle action à réaliser."; - } - this.mailchimpService.create({ templateName, to,