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 { 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<Document>(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<OfficeFolder>(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 || [],
});
}