refacto email builder

This commit is contained in:
OxSaitama 2023-10-19 15:32:06 +02:00
parent 1c175ac816
commit af6783a633
4 changed files with 20 additions and 11 deletions

View File

@ -10,11 +10,12 @@ import authHandler from "@App/middlewares/AuthHandler";
import ruleHandler from "@App/middlewares/RulesHandler";
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
import roleHandler from "@App/middlewares/RolesHandler";
import EmailBuilder from "@Common/emails/EmailBuilder";
@Controller()
@Service()
export default class DocumentsController extends ApiController {
constructor(private documentsService: DocumentsService) {
constructor(private documentsService: DocumentsService, private emailBuilder: EmailBuilder) {
super();
}
@ -70,6 +71,10 @@ export default class DocumentsController extends ApiController {
strategy: "excludeAll",
});
//create email for asked document
this.emailBuilder.sendDocumentEmails(documentEntityCreated);
//success
this.httpCreated(response, document);
} catch (error) {
@ -106,6 +111,9 @@ export default class DocumentsController extends ApiController {
//call service to get prisma entity
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
//create email for asked document
this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
//Hydrate ressource with prisma entity
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });

View File

@ -177,9 +177,10 @@ export default class DocumentsController extends ApiController {
//call service to get prisma entity
const documentEntityUpdated: Documents = await this.documentsService.refuse(uid, documentEntity, req.body.refused_reason);
//create email for asked document
// this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
// this.notificationBuilder.sendDocumentAnchoredNotificatiom(documentEntityUpdated);
this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
//Hydrate ressource with prisma entity
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });

View File

@ -2,6 +2,7 @@ import authHandler from "@App/middlewares/AuthHandler";
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
import roleHandler from "@App/middlewares/RolesHandler";
import ruleHandler from "@App/middlewares/RulesHandler";
import EmailBuilder from "@Common/emails/EmailBuilder";
import ApiController from "@Common/system/controller-pattern/ApiController";
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
@ -14,7 +15,7 @@ import { Service } from "typedi";
@Controller()
@Service()
export default class DocumentsController extends ApiController {
constructor(private documentsService: DocumentsService) {
constructor(private documentsService: DocumentsService, private emailBuilder: EmailBuilder) {
super();
}
@ -36,8 +37,6 @@ export default class DocumentsController extends ApiController {
if (!query.where) query.where = { document_type: { office: officeWhereInput } };
// query.where.document_type!.office = officeWhereInput;
//call service to get prisma entity
const documentEntities = await this.documentsService.get(query);
@ -74,6 +73,9 @@ export default class DocumentsController extends ApiController {
strategy: "excludeAll",
});
//create email for asked document
this.emailBuilder.sendDocumentEmails(documentEntityCreated);
//success
this.httpCreated(response, document);
} catch (error) {
@ -155,8 +157,7 @@ export default class DocumentsController extends ApiController {
const documentEntityUpdated: Documents = await this.documentsService.refuse(uid, documentEntity, req.body.refused_reason);
//create email for asked document
// this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
// this.notificationBuilder.sendDocumentAnchoredNotificatiom(documentEntityUpdated);
this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
//Hydrate ressource with prisma entity
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });

View File

@ -24,12 +24,11 @@ export default class EmailBuilder{
if(lastEmail.length > 0) return;
const to = document.depositor!.contact!.email;
const civility = this.getCivility(document.depositor!.contact!.civility);
const templateVariables = {
civility: civility,
first_name: document.depositor!.contact!.first_name,
last_name: document.depositor!.contact!.last_name,
office_name: document.folder!.office!.name,
link: this.variables.APP_HOST
link: `${this.variables.APP_HOST}/customer-login`
};
let templateName = ETemplates.DOCUMENT_ASKED;