diff --git a/src/common/notifications/NotificationBuilder.ts b/src/common/notifications/NotificationBuilder.ts index 0e8b9eb3..3db177a2 100644 --- a/src/common/notifications/NotificationBuilder.ts +++ b/src/common/notifications/NotificationBuilder.ts @@ -1,5 +1,5 @@ import DocumentsService from "@Services/super-admin/DocumentsService/DocumentsService"; -import { Documents } from "@prisma/client"; +import { Documents, OfficeFolders } from "@prisma/client"; import User, { Document, OfficeFolder, Vote } from "le-coffre-resources/dist/SuperAdmin"; import { Service } from "typedi"; import NotificationsService from "@Services/common/NotificationsService/NotificationsService"; @@ -41,26 +41,26 @@ export default class NotificationBuilder { }); } - public async sendDocumentAnchoredNotification(documentEntity: Documents) { - const documentPrisma = await this.documentsService.getByUid(documentEntity.uid, { - depositor: { include: { contact: true } }, - folder: { include: { folder_anchor: true, office: true, stakeholders: true } }, - }); - if (!documentPrisma) throw new Error("Document not found"); - const document = Document.hydrate(documentPrisma); - if (document.folder?.folder_anchor?.status !== "VERIFIED_ON_CHAIN") return; + public async sendFolderAnchoredNotification(folderEntity: OfficeFolders) { + if(!folderEntity.uid) return; + const officeFolderPrisma = await this.foldersService.getByUid(folderEntity.uid, + { folder_anchor: true, office: true, stakeholders: true } + ); + if (!officeFolderPrisma) throw new Error("Folder not found"); + const folder = OfficeFolder.hydrate(officeFolderPrisma); + if (folder.folder_anchor?.status !== "VERIFIED_ON_CHAIN") return; this.notificationsService.create({ message: "Le dossier " + - document.folder?.folder_number + + folder.folder_number + " - " + - document.folder?.name + + folder.name + " a été certifié. Vous pouvez désormais télécharger le certificat de dépôt pour le mettre dans la GED de votre logiciel de rédaction d'acte.", - redirection_url: `${this.backendVariables.APP_HOST}/folders/${document.folder?.uid}/documents/${document.uid}`, + redirection_url: `${this.backendVariables.APP_HOST}/folders/${folder?.uid}`, created_at: new Date(), updated_at: new Date(), - user: document.folder!.stakeholders || [], + user: folder.stakeholders || [], }); }