preprod #5

Merged
Omar merged 5 commits from preprod into main 2025-07-21 23:39:59 +00:00
Showing only changes of commit b70dee2afe - Show all commits

View File

@ -2,7 +2,7 @@ import { Response, Request } from "express";
import { Controller, Get, Post } from "@ControllerPattern/index"; import { Controller, Get, Post } from "@ControllerPattern/index";
import ApiController from "@Common/system/controller-pattern/ApiController"; import ApiController from "@Common/system/controller-pattern/ApiController";
import { Service } from "typedi"; import { Service } from "typedi";
import { Document, OfficeFolder } from "le-coffre-resources/dist/Notary"; import { Document, OfficeFolder, File } from "le-coffre-resources/dist/Notary";
import { getFolderHashes, getFolderFilesUid } from "@Common/optics/notary"; import { getFolderHashes, getFolderFilesUid } from "@Common/optics/notary";
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService"; import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository"; import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository";
@ -162,24 +162,34 @@ export default class OfficeFoldersController extends ApiController {
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" }); const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
// Check if every document is validated in a folder
const documents = officeFolder.documents ?? []; const documents = officeFolder.documents ?? [];
const documentsValidated = documents.filter((document) => {
let documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" }); if (documents.length === 0) {
return documentHydrated.document_status === "VALIDATED"; this.httpBadRequest(response, "OfficeFolder has no documents at all");
return;
}
const hasInvalidDocument = documents.some((document: any) => {
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
return documentHydrated.document_status !== "VALIDATED" &&
documentHydrated.document_status !== "REFUSED";
}); });
if (documentsValidated.length !== documents.length && documents.length !== 0) { if (hasInvalidDocument) {
this.httpBadRequest(response, "Cannot anchor a folder with non validated documents"); this.httpBadRequest(response, "OfficeFolder has non validated documents");
return; return;
} }
const folderHashes = getFolderHashes(officeFolder); const folderHashes: string[] = [];
documents.forEach((document: any) => {
if (folderHashes.length === 0) { const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
this.httpNotFoundRequest(response, "No file hash to anchor"); if (documentHydrated.document_status === "VALIDATED") {
return; documentHydrated.files?.forEach((file: any) => {
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
folderHashes.push(fileHydrated.hash);
});
} }
});
const sortedHashes = [...folderHashes].sort(); const sortedHashes = [...folderHashes].sort();
const data = await this.secureService.anchor(sortedHashes); const data = await this.secureService.anchor(sortedHashes);