diff --git a/src/app/api/idnot/UserController.ts b/src/app/api/idnot/UserController.ts index 41cfb63a..0eb744c5 100644 --- a/src/app/api/idnot/UserController.ts +++ b/src/app/api/idnot/UserController.ts @@ -50,7 +50,7 @@ export default class UserController extends ApiController { if (!user) { console.error("User not found"); - this.httpUnauthorized(response, "User not found"); + this.httpUnauthorized(response, "Email not found"); return; } diff --git a/src/app/api/notary/DocumentsNotaryController.ts b/src/app/api/notary/DocumentsNotaryController.ts index 900a54d5..fd3da714 100644 --- a/src/app/api/notary/DocumentsNotaryController.ts +++ b/src/app/api/notary/DocumentsNotaryController.ts @@ -1,4 +1,5 @@ import authHandler from "@App/middlewares/AuthHandler"; +import EmailBuilder from "@Common/emails/EmailBuilder"; import ApiController from "@Common/system/controller-pattern/ApiController"; import { Controller, Delete, Get, Post } from "@ControllerPattern/index"; import { DocumentsNotary, Prisma } from "@prisma/client"; @@ -20,6 +21,7 @@ export default class DocumentsNotaryController extends ApiController { private customerService: CustomersService, private userService: UsersService, private filesNotaryService: FilesNotaryService, + private emailBuilder: EmailBuilder, ) { super(); } @@ -92,6 +94,9 @@ export default class DocumentsNotaryController extends ApiController { } const documentNotary = await this.documentsNotaryService.getByUid(documentNotaryEntityCreated.uid); + if(!documentNotary) return; + + await this.emailBuilder.sendDocumentNotaryEmails(documentNotary); const document = DocumentNotary.hydrate(documentNotary!); //success diff --git a/src/app/middlewares/OfficeMembershipHandlers/FolderHandler.ts b/src/app/middlewares/OfficeMembershipHandlers/FolderHandler.ts index dc623c5f..bea0ae54 100644 --- a/src/app/middlewares/OfficeMembershipHandlers/FolderHandler.ts +++ b/src/app/middlewares/OfficeMembershipHandlers/FolderHandler.ts @@ -13,6 +13,7 @@ export default async function folderHandler(req: Request, response: Response, ne const deed = req.body.deed; const folderNumber = req.body.folder_number; const stakeHolders = req.body.stakeholders as any[]; + const description = req.body.description; if (office && office.uid != officeId) { response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office"); @@ -31,6 +32,11 @@ export default async function folderHandler(req: Request, response: Response, ne } } + if (description && description.length > 250) { + response.status(HttpCodes.VALIDATION_ERROR).send([{ property: "description", constraints: { description: "La description dépasse 250 caractères" } }]); + return; + } + if (stakeHolders && stakeHolders.length === 0) { response .status(HttpCodes.VALIDATION_ERROR) diff --git a/src/common/emails/EmailBuilder.ts b/src/common/emails/EmailBuilder.ts index 7d795ba9..0d12f27c 100644 --- a/src/common/emails/EmailBuilder.ts +++ b/src/common/emails/EmailBuilder.ts @@ -1,5 +1,5 @@ import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService"; -import { Documents } from "@prisma/client"; +import { Documents, DocumentsNotary } from "@prisma/client"; import { Document } from "le-coffre-resources/dist/SuperAdmin"; import { Service } from "typedi"; import { ETemplates } from "./Templates/EmailTemplates"; @@ -7,7 +7,8 @@ import MailchimpService from "@Services/common/MailchimpService/MailchimpService import { BackendVariables } from "@Common/config/variables/Variables"; import UsersService from "@Services/super-admin/UsersService/UsersService"; import User from "le-coffre-resources/dist/SuperAdmin"; -import { Customer } from "le-coffre-resources/dist/Notary"; +import { Customer, DocumentNotary } from "le-coffre-resources/dist/Notary"; +import DocumentsNotaryService from "@Services/notary/DocumentsNotaryService/DocumentsNotaryService"; @Service() export default class EmailBuilder { @@ -16,6 +17,7 @@ export default class EmailBuilder { private documentsService: DocumentsService, protected variables: BackendVariables, private usersService: UsersService, + private documentNotaryService : DocumentsNotaryService, ) {} public async sendDocumentEmails(documentEntity: Documents) { @@ -166,4 +168,49 @@ export default class EmailBuilder { lastTrySendDate: null, }); } + + public async sendDocumentNotaryEmails(documentEntity: DocumentsNotary) { + const templateName = ETemplates.DOCUMENT_SEND; + const subject = "Votre notaire vous a envoyé des documents."; + + const documentPrisma = await this.documentNotaryService.getByUid(documentEntity.uid, { + depositor: { include: { contact: true } }, + folder: { include: { office: true } }, + customer: { include: { contact: true } }, + }); + if (!documentPrisma) throw new Error("Document not found"); + const document = DocumentNotary.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.customer?.contact?.email, + OR: [{ sentAt: { gte: new Date(Date.now() - 3600000) } }, { sentAt: null }], + templateName: templateName, + }, + }); + if (lastEmail.length > 0) return; + + const to = document.customer!.contact!.email; + const templateVariables = { + first_name: document.customer?.contact?.first_name, + last_name: document.customer?.contact?.last_name, + office_name: document.folder!.office!.name, + link: `${this.variables.APP_HOST}/customer-login`, + }; + + this.mailchimpService.create({ + templateName, + to, + subject, + templateVariables, + uid: "", + from: null, + cc: [], + cci: [], + sentAt: null, + nbTrySend: null, + lastTrySendDate: null, + }); + } } diff --git a/src/common/emails/Templates/EmailTemplates.ts b/src/common/emails/Templates/EmailTemplates.ts index 4943b885..265d824d 100644 --- a/src/common/emails/Templates/EmailTemplates.ts +++ b/src/common/emails/Templates/EmailTemplates.ts @@ -4,4 +4,5 @@ export const ETemplates = { DOCUMENT_RECAP: "DOCUMENT_RECAP", SUBSCRIPTION_INVITATION: "SUBSCRIPTION_INVITATION", DOCUMENT_REMINDER: "DOCUMENT_REMINDER", + DOCUMENT_SEND: "DOCUMENT_SEND", }; \ No newline at end of file diff --git a/src/services/common/IdNotService/IdNotService.ts b/src/services/common/IdNotService/IdNotService.ts index 3226f38e..aecc1372 100644 --- a/src/services/common/IdNotService/IdNotService.ts +++ b/src/services/common/IdNotService/IdNotService.ts @@ -407,6 +407,8 @@ export default class IdNotService extends BaseService { return null; } + console.log("officeLocationData", officeLocationData); + const office = await this.officeService.get({ where: { idNot: decodedToken.entity_idn } }); // if(officeLocationData.result[0]!.adrGeoCodePostal.slice(0,2) !== "35") { diff --git a/src/services/customer/CustomersService/CustomersService.ts b/src/services/customer/CustomersService/CustomersService.ts index fcc02d17..7d64e0aa 100644 --- a/src/services/customer/CustomersService/CustomersService.ts +++ b/src/services/customer/CustomersService/CustomersService.ts @@ -358,7 +358,7 @@ export default class CustomersService extends BaseService { } private async sendSmsCodeToCustomer(totpPin: number, customer: Customer) { - const message = "Votre code de vérification LEcoffre.io est : " + totpPin.toString(); + const message = "Votre code de vérification LeCoffre est : " + totpPin.toString(); // Sélectionnez le fournisseur de SMS en fonction de la variable d'environnement //const selectedProvider = this.variables.SMS_PROVIDER === "OVH" ? this.ovhService : this.smsFactorService;