Merge branch 'preprod'

This commit is contained in:
Vins 2024-11-12 10:39:36 +01:00
commit f2d8d2ca28
6 changed files with 64 additions and 3 deletions

View File

@ -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;
}

View File

@ -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>(documentNotary!);
//success

View File

@ -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)

View File

@ -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<DocumentNotary>(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,
});
}
}

View File

@ -4,4 +4,5 @@ export const ETemplates = {
DOCUMENT_RECAP: "DOCUMENT_RECAP",
SUBSCRIPTION_INVITATION: "SUBSCRIPTION_INVITATION",
DOCUMENT_REMINDER: "DOCUMENT_REMINDER",
DOCUMENT_SEND: "DOCUMENT_SEND",
};

View File

@ -418,6 +418,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") {