send anchoring notification (#107)

This commit is contained in:
Arnaud D. Natali 2023-10-02 11:25:06 +02:00 committed by GitHub
commit 9725eed815
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -11,6 +11,7 @@ import authHandler from "@App/middlewares/AuthHandler";
import ruleHandler from "@App/middlewares/RulesHandler";
import folderHandler from "@App/middlewares/OfficeMembershipHandlers/FolderHandler";
import OfficeFolderAnchor from "le-coffre-resources/dist/Notary/OfficeFolderAnchor";
import NotificationBuilder from "@Common/notifications/NotificationBuilder";
const hydrateOfficeFolderAnchor = (data: any): OfficeFolderAnchor =>
OfficeFolderAnchor.hydrate<OfficeFolderAnchor>(
@ -33,7 +34,12 @@ const hydrateOfficeFolderAnchor = (data: any): OfficeFolderAnchor =>
@Controller()
@Service()
export default class OfficeFoldersController extends ApiController {
constructor(private secureService: SecureService, private officeFolderAnchorsRepository: OfficeFolderAnchorsRepository, private officeFoldersService: OfficeFoldersService) {
constructor(
private secureService: SecureService,
private officeFolderAnchorsRepository: OfficeFolderAnchorsRepository,
private officeFoldersService: OfficeFoldersService,
private notificationBuilder: NotificationBuilder,
) {
super();
}
@ -76,7 +82,7 @@ export default class OfficeFoldersController extends ApiController {
const sortedHashes = [...folderHashes].sort();
const buffer = await this.secureService.download(sortedHashes);
response.setHeader('Content-Type', 'application/pdf');
response.setHeader("Content-Type", "application/pdf");
this.httpSuccess(response, buffer);
} catch (error) {
this.httpInternalError(response, error);
@ -139,9 +145,7 @@ export default class OfficeFoldersController extends ApiController {
const officeFolderAnchor = hydrateOfficeFolderAnchor(data);
const newOfficeFolderAnchor = await this.officeFolderAnchorsRepository.create(
officeFolderAnchor
);
const newOfficeFolderAnchor = await this.officeFolderAnchorsRepository.create(officeFolderAnchor);
await this.officeFoldersService.update(
uid,
@ -198,14 +202,14 @@ export default class OfficeFoldersController extends ApiController {
});
if (!officeFolderAnchorFound || !officeFolderAnchorFound.uid) {
this.httpNotFoundRequest(response, {error: "Not anchored", hash_sources: sortedHashes});
this.httpNotFoundRequest(response, { error: "Not anchored", hash_sources: sortedHashes });
return;
}
const data = await this.secureService.verify(sortedHashes);
if (data.errors || data.transactions.length === 0) {
this.httpNotFoundRequest(response, {error: "Not anchored", hash_sources: sortedHashes});
this.httpNotFoundRequest(response, { error: "Not anchored", hash_sources: sortedHashes });
return;
}
@ -213,9 +217,12 @@ export default class OfficeFoldersController extends ApiController {
const updatedOfficeFolderAnchor = await this.officeFolderAnchorsRepository.update(
officeFolderAnchorFound.uid,
officeFolderAnchor
officeFolderAnchor,
);
if (officeFolderAnchorFound.status !== "VERIFIED_ON_CHAIN" && officeFolderAnchor.status === "VERIFIED_ON_CHAIN")
this.notificationBuilder.sendFolderAnchoredNotification(officeFolderFound);
this.httpSuccess(response, updatedOfficeFolderAnchor);
return;
} catch (error) {