Merge branch 'fix_download_certificate' into legacy_dev
All checks were successful
All checks were successful
This commit is contained in:
commit
c33d4faacd
@ -3,7 +3,7 @@ import { Controller, Get, Post } from "@ControllerPattern/index";
|
||||
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||
import { Service } from "typedi";
|
||||
import { Document, OfficeFolder, File } from "le-coffre-resources/dist/Notary";
|
||||
import { getFolderHashes, getFolderFilesUid } from "@Common/optics/notary";
|
||||
import { getFolderFilesUid } from "@Common/optics/notary";
|
||||
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||
import OfficeFolderAnchorsRepository from "@Repositories/OfficeFolderAnchorsRepository";
|
||||
import FilesService from "@Services/common/FilesService/FilesService";
|
||||
@ -49,6 +49,27 @@ export default class OfficeFoldersController extends ApiController {
|
||||
super();
|
||||
}
|
||||
|
||||
private getValidatedDocumentHashes(officeFolder: OfficeFolder): string[] {
|
||||
const documents = officeFolder.documents ?? [];
|
||||
|
||||
if (documents.length === 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const folderHashes: string[] = [];
|
||||
documents.forEach((document: any) => {
|
||||
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
|
||||
if (documentHydrated.document_status === "VALIDATED") {
|
||||
documentHydrated.files?.forEach((file: any) => {
|
||||
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
|
||||
folderHashes.push(fileHydrated.hash);
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
return folderHashes.sort();
|
||||
}
|
||||
|
||||
/**
|
||||
* @description Download a folder anchoring proof document along with all accessible files
|
||||
*/
|
||||
@ -79,15 +100,14 @@ export default class OfficeFoldersController extends ApiController {
|
||||
}
|
||||
|
||||
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
|
||||
const folderHashes = getFolderHashes(officeFolder);
|
||||
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
|
||||
const folderFilesUid = getFolderFilesUid(officeFolder);
|
||||
|
||||
if (folderHashes.length === 0) {
|
||||
if (sortedHashes.length === 0) {
|
||||
this.httpNotFoundRequest(response, "No file hash to anchor");
|
||||
return;
|
||||
}
|
||||
|
||||
const sortedHashes = [...folderHashes].sort();
|
||||
const anchoringProof = await this.secureService.download(sortedHashes, officeFolder.office!.name);
|
||||
|
||||
|
||||
@ -180,18 +200,13 @@ export default class OfficeFoldersController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const folderHashes: string[] = [];
|
||||
documents.forEach((document: any) => {
|
||||
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
|
||||
if (documentHydrated.document_status === "VALIDATED") {
|
||||
documentHydrated.files?.forEach((file: any) => {
|
||||
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
|
||||
folderHashes.push(fileHydrated.hash);
|
||||
});
|
||||
}
|
||||
});
|
||||
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
|
||||
|
||||
if (sortedHashes.length === 0) {
|
||||
this.httpBadRequest(response, "No file hash to anchor");
|
||||
return;
|
||||
}
|
||||
|
||||
const sortedHashes = [...folderHashes].sort();
|
||||
const data = await this.secureService.anchor(sortedHashes);
|
||||
|
||||
const officeFolderAnchor = hydrateOfficeFolderAnchor(data);
|
||||
@ -248,23 +263,13 @@ export default class OfficeFoldersController extends ApiController {
|
||||
return;
|
||||
}
|
||||
|
||||
const folderHashes: string[] = [];
|
||||
documents.forEach((document: any) => {
|
||||
const documentHydrated = Document.hydrate<Document>(document, { strategy: "excludeAll" });
|
||||
if (documentHydrated.document_status === "VALIDATED") {
|
||||
documentHydrated.files?.forEach((file: any) => {
|
||||
const fileHydrated = File.hydrate<File>(file, { strategy: "excludeAll" });
|
||||
folderHashes.push(fileHydrated.hash);
|
||||
});
|
||||
}
|
||||
});
|
||||
const sortedHashes = this.getValidatedDocumentHashes(officeFolder);
|
||||
|
||||
if (folderHashes.length === 0) {
|
||||
if (sortedHashes.length === 0) {
|
||||
this.httpNotFoundRequest(response, "No file hash to anchor");
|
||||
return;
|
||||
}
|
||||
|
||||
const sortedHashes = [...folderHashes].sort();
|
||||
const officeFolderAnchorFound = OfficeFolderAnchor.hydrate<OfficeFolderAnchor>(officeFolderFound.folder_anchor, {
|
||||
strategy: "excludeAll",
|
||||
});
|
||||
|
@ -95,7 +95,7 @@ export default class NotificationBuilder {
|
||||
redirection_url: "",
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
user: [user] || [],
|
||||
user: user ? [user] : [],
|
||||
});
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ export default class NotificationBuilder {
|
||||
redirection_url: "",
|
||||
created_at: new Date(),
|
||||
updated_at: new Date(),
|
||||
user: [user] || [],
|
||||
user: user ? [user] : [],
|
||||
});
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user