refacto folder anchor notification

This commit is contained in:
OxSaitama 2023-09-29 18:01:37 +02:00
parent 7a5133a1f5
commit 6d4d4f05e5

View File

@ -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, OfficeFolders } from "@prisma/client";
import User, { Document, OfficeFolder, Vote } from "le-coffre-resources/dist/SuperAdmin"; import User, { Document, OfficeFolder, Vote } from "le-coffre-resources/dist/SuperAdmin";
import { Service } from "typedi"; import { Service } from "typedi";
import NotificationsService from "@Services/common/NotificationsService/NotificationsService"; import NotificationsService from "@Services/common/NotificationsService/NotificationsService";
@ -41,26 +41,26 @@ export default class NotificationBuilder {
}); });
} }
public async sendDocumentAnchoredNotification(documentEntity: Documents) { public async sendFolderAnchoredNotification(folderEntity: OfficeFolders) {
const documentPrisma = await this.documentsService.getByUid(documentEntity.uid, { if(!folderEntity.uid) return;
depositor: { include: { contact: true } }, const officeFolderPrisma = await this.foldersService.getByUid(folderEntity.uid,
folder: { include: { folder_anchor: true, office: true, stakeholders: true } }, { folder_anchor: true, office: true, stakeholders: true }
}); );
if (!documentPrisma) throw new Error("Document not found"); if (!officeFolderPrisma) throw new Error("Folder not found");
const document = Document.hydrate<Document>(documentPrisma); const folder = OfficeFolder.hydrate<OfficeFolder>(officeFolderPrisma);
if (document.folder?.folder_anchor?.status !== "VERIFIED_ON_CHAIN") return; if (folder.folder_anchor?.status !== "VERIFIED_ON_CHAIN") return;
this.notificationsService.create({ this.notificationsService.create({
message: message:
"Le dossier " + "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.", " 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(), created_at: new Date(),
updated_at: new Date(), updated_at: new Date(),
user: document.folder!.stakeholders || [], user: folder.stakeholders || [],
}); });
} }