refacto email builder
This commit is contained in:
parent
1c175ac816
commit
af6783a633
@ -10,11 +10,12 @@ import authHandler from "@App/middlewares/AuthHandler";
|
|||||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
||||||
import roleHandler from "@App/middlewares/RolesHandler";
|
import roleHandler from "@App/middlewares/RolesHandler";
|
||||||
|
import EmailBuilder from "@Common/emails/EmailBuilder";
|
||||||
|
|
||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class DocumentsController extends ApiController {
|
export default class DocumentsController extends ApiController {
|
||||||
constructor(private documentsService: DocumentsService) {
|
constructor(private documentsService: DocumentsService, private emailBuilder: EmailBuilder) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,6 +71,10 @@ export default class DocumentsController extends ApiController {
|
|||||||
strategy: "excludeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//create email for asked document
|
||||||
|
this.emailBuilder.sendDocumentEmails(documentEntityCreated);
|
||||||
|
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpCreated(response, document);
|
this.httpCreated(response, document);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
@ -106,6 +111,9 @@ export default class DocumentsController extends ApiController {
|
|||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
const documentEntityUpdated: Documents = await this.documentsService.update(uid, documentEntity);
|
||||||
|
|
||||||
|
//create email for asked document
|
||||||
|
this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||||
|
|
||||||
|
@ -177,9 +177,10 @@ export default class DocumentsController extends ApiController {
|
|||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
const documentEntityUpdated: Documents = await this.documentsService.refuse(uid, documentEntity, req.body.refused_reason);
|
const documentEntityUpdated: Documents = await this.documentsService.refuse(uid, documentEntity, req.body.refused_reason);
|
||||||
|
|
||||||
|
|
||||||
//create email for asked document
|
//create email for asked document
|
||||||
// this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
||||||
// this.notificationBuilder.sendDocumentAnchoredNotificatiom(documentEntityUpdated);
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||||
|
@ -2,6 +2,7 @@ import authHandler from "@App/middlewares/AuthHandler";
|
|||||||
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
import documentHandler from "@App/middlewares/OfficeMembershipHandlers/DocumentHandler";
|
||||||
import roleHandler from "@App/middlewares/RolesHandler";
|
import roleHandler from "@App/middlewares/RolesHandler";
|
||||||
import ruleHandler from "@App/middlewares/RulesHandler";
|
import ruleHandler from "@App/middlewares/RulesHandler";
|
||||||
|
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, Put } from "@ControllerPattern/index";
|
import { Controller, Delete, Get, Post, Put } from "@ControllerPattern/index";
|
||||||
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
import { Documents, EDocumentStatus, Prisma } from "@prisma/client";
|
||||||
@ -14,7 +15,7 @@ import { Service } from "typedi";
|
|||||||
@Controller()
|
@Controller()
|
||||||
@Service()
|
@Service()
|
||||||
export default class DocumentsController extends ApiController {
|
export default class DocumentsController extends ApiController {
|
||||||
constructor(private documentsService: DocumentsService) {
|
constructor(private documentsService: DocumentsService, private emailBuilder: EmailBuilder) {
|
||||||
super();
|
super();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -36,8 +37,6 @@ export default class DocumentsController extends ApiController {
|
|||||||
|
|
||||||
if (!query.where) query.where = { document_type: { office: officeWhereInput } };
|
if (!query.where) query.where = { document_type: { office: officeWhereInput } };
|
||||||
|
|
||||||
// query.where.document_type!.office = officeWhereInput;
|
|
||||||
|
|
||||||
//call service to get prisma entity
|
//call service to get prisma entity
|
||||||
|
|
||||||
const documentEntities = await this.documentsService.get(query);
|
const documentEntities = await this.documentsService.get(query);
|
||||||
@ -74,6 +73,9 @@ export default class DocumentsController extends ApiController {
|
|||||||
strategy: "excludeAll",
|
strategy: "excludeAll",
|
||||||
});
|
});
|
||||||
|
|
||||||
|
//create email for asked document
|
||||||
|
this.emailBuilder.sendDocumentEmails(documentEntityCreated);
|
||||||
|
|
||||||
//success
|
//success
|
||||||
this.httpCreated(response, document);
|
this.httpCreated(response, document);
|
||||||
} catch (error) {
|
} 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);
|
const documentEntityUpdated: Documents = await this.documentsService.refuse(uid, documentEntity, req.body.refused_reason);
|
||||||
|
|
||||||
//create email for asked document
|
//create email for asked document
|
||||||
// this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
this.emailBuilder.sendDocumentEmails(documentEntityUpdated);
|
||||||
// this.notificationBuilder.sendDocumentAnchoredNotificatiom(documentEntityUpdated);
|
|
||||||
|
|
||||||
//Hydrate ressource with prisma entity
|
//Hydrate ressource with prisma entity
|
||||||
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
const document = Document.hydrate<Document>(documentEntityUpdated, { strategy: "excludeAll" });
|
||||||
|
@ -24,12 +24,11 @@ export default class EmailBuilder{
|
|||||||
if(lastEmail.length > 0) return;
|
if(lastEmail.length > 0) return;
|
||||||
|
|
||||||
const to = document.depositor!.contact!.email;
|
const to = document.depositor!.contact!.email;
|
||||||
const civility = this.getCivility(document.depositor!.contact!.civility);
|
|
||||||
const templateVariables = {
|
const templateVariables = {
|
||||||
civility: civility,
|
first_name: document.depositor!.contact!.first_name,
|
||||||
last_name: document.depositor!.contact!.last_name,
|
last_name: document.depositor!.contact!.last_name,
|
||||||
office_name: document.folder!.office!.name,
|
office_name: document.folder!.office!.name,
|
||||||
link: this.variables.APP_HOST
|
link: `${this.variables.APP_HOST}/customer-login`
|
||||||
};
|
};
|
||||||
|
|
||||||
let templateName = ETemplates.DOCUMENT_ASKED;
|
let templateName = ETemplates.DOCUMENT_ASKED;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user