add OfficeFolderAnchorsController
- create a job for anchoring all hashes in a folder - monitor the status of an anchoring
This commit is contained in:
parent
b448aea01e
commit
dc5eb4cb52
108
src/app/api/notary/OfficeFolderAnchorsController.ts
Normal file
108
src/app/api/notary/OfficeFolderAnchorsController.ts
Normal file
@ -0,0 +1,108 @@
|
|||||||
|
import { Response, Request } from "express";
|
||||||
|
import { Controller, Get, Post } from "@ControllerPattern/index";
|
||||||
|
import ApiController from "@Common/system/controller-pattern/ApiController";
|
||||||
|
import { Service } from "typedi";
|
||||||
|
import { OfficeFolder } from "le-coffre-resources/dist/Notary";
|
||||||
|
import { getFolderHashes } from "@Common/optics/notary";
|
||||||
|
import OfficeFoldersService from "@Services/notary/OfficeFoldersService/OfficeFoldersService";
|
||||||
|
import SecureService from "@Services/common/SecureService/SecureService";
|
||||||
|
|
||||||
|
@Controller()
|
||||||
|
@Service()
|
||||||
|
export default class OfficeFoldersController extends ApiController {
|
||||||
|
constructor(private secureService: SecureService, private officeFoldersService: OfficeFoldersService) {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Create a new folder anchor
|
||||||
|
*/
|
||||||
|
@Post("/api/v1/notary/anchors/:uid")
|
||||||
|
protected async post(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = {
|
||||||
|
documents: {
|
||||||
|
include: {
|
||||||
|
files: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const officeFolderFound = await this.officeFoldersService.getByUid(uid, query);
|
||||||
|
|
||||||
|
if (!officeFolderFound) {
|
||||||
|
this.httpNotFoundRequest(response, "Office folder not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
|
||||||
|
const folderHashes = getFolderHashes(officeFolder);
|
||||||
|
|
||||||
|
if (folderHashes.length === 0) {
|
||||||
|
this.httpNotFoundRequest(response, "No file hash to anchor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortedHashes = [...folderHashes].sort();
|
||||||
|
const anchor = await this.secureService.anchor(sortedHashes);
|
||||||
|
|
||||||
|
this.httpSuccess(response, anchor);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @description Verify a folder anchor status
|
||||||
|
*/
|
||||||
|
@Get("/api/v1/notary/anchors/:uid")
|
||||||
|
protected async get(req: Request, response: Response) {
|
||||||
|
try {
|
||||||
|
const uid = req.params["uid"];
|
||||||
|
|
||||||
|
if (!uid) {
|
||||||
|
this.httpBadRequest(response, "No uid provided");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const query = {
|
||||||
|
documents: {
|
||||||
|
include: {
|
||||||
|
files: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const officeFolderFound = await this.officeFoldersService.getByUid(uid, query);
|
||||||
|
|
||||||
|
if (!officeFolderFound) {
|
||||||
|
this.httpNotFoundRequest(response, "Office folder not found");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const officeFolder = OfficeFolder.hydrate<OfficeFolder>(officeFolderFound, { strategy: "excludeAll" });
|
||||||
|
const folderHashes = getFolderHashes(officeFolder);
|
||||||
|
|
||||||
|
if (folderHashes.length === 0) {
|
||||||
|
this.httpNotFoundRequest(response, "No file hash to anchor");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const sortedHashes = [...folderHashes].sort();
|
||||||
|
const anchor = await this.secureService.verify(sortedHashes);
|
||||||
|
|
||||||
|
this.httpSuccess(response, anchor);
|
||||||
|
} catch (error) {
|
||||||
|
this.httpInternalError(response, error);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -41,6 +41,7 @@ import OfficeRolesControllerNotary from "./api/notary/OfficeRolesController";
|
|||||||
import FilesControllerCustomer from "./api/customer/FilesController";
|
import FilesControllerCustomer from "./api/customer/FilesController";
|
||||||
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
import DocumentsControllerCustomer from "./api/customer/DocumentsController";
|
||||||
import OfficeFoldersController from "./api/customer/OfficeFoldersController";
|
import OfficeFoldersController from "./api/customer/OfficeFoldersController";
|
||||||
|
import OfficeFolderAnchorsController from "./api/notary/OfficeFolderAnchorsController";
|
||||||
import CustomersController from "./api/customer/CustomersController";
|
import CustomersController from "./api/customer/CustomersController";
|
||||||
import AppointmentsController from "./api/super-admin/AppointmentsController";
|
import AppointmentsController from "./api/super-admin/AppointmentsController";
|
||||||
import VotesController from "./api/super-admin/VotesController";
|
import VotesController from "./api/super-admin/VotesController";
|
||||||
@ -98,6 +99,7 @@ export default {
|
|||||||
Container.get(FilesControllerCustomer);
|
Container.get(FilesControllerCustomer);
|
||||||
Container.get(DocumentsControllerCustomer);
|
Container.get(DocumentsControllerCustomer);
|
||||||
Container.get(OfficeFoldersController);
|
Container.get(OfficeFoldersController);
|
||||||
|
Container.get(OfficeFolderAnchorsController);
|
||||||
Container.get(CustomersController)
|
Container.get(CustomersController)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
Loading…
x
Reference in New Issue
Block a user