46 lines
1.8 KiB
TypeScript
46 lines
1.8 KiB
TypeScript
|
|
import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService";
|
|
import { Documents } from "@prisma/client";
|
|
import { Document } from "le-coffre-resources/dist/SuperAdmin";
|
|
import { Service } from "typedi";
|
|
import NotificationsService from "@Services/common/NotificationsService/NotificationsService";
|
|
|
|
@Service()
|
|
export default class NotificationBuilder {
|
|
public constructor(private notificationsService : NotificationsService, private documentsService: DocumentsService){}
|
|
|
|
public async sendDocumentDepositedNotification(documentEntity: Documents){
|
|
if(documentEntity.document_status !== "DEPOSITED") return;
|
|
|
|
const documentPrisma = await this.documentsService.getByUid(documentEntity.uid, { depositor: {include: {contact: true}}, folder:{include:{ office: true, stakeholders: true}} });
|
|
if(!documentPrisma) throw new Error("Document not found");
|
|
const document = Document.hydrate<Document>(documentPrisma);
|
|
|
|
this.notificationsService.create({
|
|
message: "Document déposé",
|
|
redirection_url: "",
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
user : document.folder!.stakeholders || [],
|
|
});
|
|
|
|
}
|
|
|
|
public async sendDocumentAnchoredNotificatiom(documentEntity: Documents){
|
|
if(documentEntity.document_status !== "ANCHORED") return;
|
|
|
|
const documentPrisma = await this.documentsService.getByUid(documentEntity.uid, { depositor: {include: {contact: true}}, folder:{include:{ office: true, stakeholders: true}} });
|
|
if(!documentPrisma) throw new Error("Document not found");
|
|
const document = Document.hydrate<Document>(documentPrisma);
|
|
|
|
this.notificationsService.create({
|
|
message: "Document ancré",
|
|
redirection_url: "",
|
|
created_at: new Date(),
|
|
updated_at: new Date(),
|
|
user : document.folder!.stakeholders || [],
|
|
});
|
|
|
|
}
|
|
}
|