Merge branch 'preprod'
This commit is contained in:
commit
f2d8d2ca28
@ -50,7 +50,7 @@ export default class UserController extends ApiController {
|
|||||||
|
|
||||||
if (!user) {
|
if (!user) {
|
||||||
console.error("User not found");
|
console.error("User not found");
|
||||||
this.httpUnauthorized(response, "User not found");
|
this.httpUnauthorized(response, "Email not found");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
import authHandler from "@App/middlewares/AuthHandler";
|
import authHandler from "@App/middlewares/AuthHandler";
|
||||||
|
import EmailBuilder from "@Common/emails/EmailBuilder";
|
||||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
import { Controller, Delete, Get, Post } from "@ControllerPattern/index";
|
import { Controller, Delete, Get, Post } from "@ControllerPattern/index";
|
||||||
import { DocumentsNotary, Prisma } from "@prisma/client";
|
import { DocumentsNotary, Prisma } from "@prisma/client";
|
||||||
@ -20,6 +21,7 @@ export default class DocumentsNotaryController extends ApiController {
|
|||||||
private customerService: CustomersService,
|
private customerService: CustomersService,
|
||||||
private userService: UsersService,
|
private userService: UsersService,
|
||||||
private filesNotaryService: FilesNotaryService,
|
private filesNotaryService: FilesNotaryService,
|
||||||
|
private emailBuilder: EmailBuilder,
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
@ -92,6 +94,9 @@ export default class DocumentsNotaryController extends ApiController {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const documentNotary = await this.documentsNotaryService.getByUid(documentNotaryEntityCreated.uid);
|
const documentNotary = await this.documentsNotaryService.getByUid(documentNotaryEntityCreated.uid);
|
||||||
|
if(!documentNotary) return;
|
||||||
|
|
||||||
|
await this.emailBuilder.sendDocumentNotaryEmails(documentNotary);
|
||||||
|
|
||||||
const document = DocumentNotary.hydrate<DocumentNotary>(documentNotary!);
|
const document = DocumentNotary.hydrate<DocumentNotary>(documentNotary!);
|
||||||
//success
|
//success
|
||||||
|
@ -13,6 +13,7 @@ export default async function folderHandler(req: Request, response: Response, ne
|
|||||||
const deed = req.body.deed;
|
const deed = req.body.deed;
|
||||||
const folderNumber = req.body.folder_number;
|
const folderNumber = req.body.folder_number;
|
||||||
const stakeHolders = req.body.stakeholders as any[];
|
const stakeHolders = req.body.stakeholders as any[];
|
||||||
|
const description = req.body.description;
|
||||||
|
|
||||||
if (office && office.uid != officeId) {
|
if (office && office.uid != officeId) {
|
||||||
response.status(HttpCodes.UNAUTHORIZED).send("Unauthorized with this office");
|
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) {
|
if (stakeHolders && stakeHolders.length === 0) {
|
||||||
response
|
response
|
||||||
.status(HttpCodes.VALIDATION_ERROR)
|
.status(HttpCodes.VALIDATION_ERROR)
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
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 { Document } from "le-coffre-resources/dist/SuperAdmin";
|
||||||
import { Service } from "typedi";
|
import { Service } from "typedi";
|
||||||
import { ETemplates } from "./Templates/EmailTemplates";
|
import { ETemplates } from "./Templates/EmailTemplates";
|
||||||
@ -7,7 +7,8 @@ import MailchimpService from "@Services/common/MailchimpService/MailchimpService
|
|||||||
import { BackendVariables } from "@Common/config/variables/Variables";
|
import { BackendVariables } from "@Common/config/variables/Variables";
|
||||||
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
import UsersService from "@Services/super-admin/UsersService/UsersService";
|
||||||
import User from "le-coffre-resources/dist/SuperAdmin";
|
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()
|
@Service()
|
||||||
export default class EmailBuilder {
|
export default class EmailBuilder {
|
||||||
@ -16,6 +17,7 @@ export default class EmailBuilder {
|
|||||||
private documentsService: DocumentsService,
|
private documentsService: DocumentsService,
|
||||||
protected variables: BackendVariables,
|
protected variables: BackendVariables,
|
||||||
private usersService: UsersService,
|
private usersService: UsersService,
|
||||||
|
private documentNotaryService : DocumentsNotaryService,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
public async sendDocumentEmails(documentEntity: Documents) {
|
public async sendDocumentEmails(documentEntity: Documents) {
|
||||||
@ -166,4 +168,49 @@ export default class EmailBuilder {
|
|||||||
lastTrySendDate: null,
|
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,
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,4 +4,5 @@ export const ETemplates = {
|
|||||||
DOCUMENT_RECAP: "DOCUMENT_RECAP",
|
DOCUMENT_RECAP: "DOCUMENT_RECAP",
|
||||||
SUBSCRIPTION_INVITATION: "SUBSCRIPTION_INVITATION",
|
SUBSCRIPTION_INVITATION: "SUBSCRIPTION_INVITATION",
|
||||||
DOCUMENT_REMINDER: "DOCUMENT_REMINDER",
|
DOCUMENT_REMINDER: "DOCUMENT_REMINDER",
|
||||||
|
DOCUMENT_SEND: "DOCUMENT_SEND",
|
||||||
};
|
};
|
@ -418,6 +418,8 @@ export default class IdNotService extends BaseService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
console.log("officeLocationData", officeLocationData);
|
||||||
|
|
||||||
const office = await this.officeService.get({ where: { idNot: decodedToken.entity_idn } });
|
const office = await this.officeService.get({ where: { idNot: decodedToken.entity_idn } });
|
||||||
|
|
||||||
// if(officeLocationData.result[0]!.adrGeoCodePostal.slice(0,2) !== "35") {
|
// if(officeLocationData.result[0]!.adrGeoCodePostal.slice(0,2) !== "35") {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user