From 279ea66a5022ad2444eead47344ab5898e014ba9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFs=20Mansot?= <26844641+devfull@users.noreply.github.com> Date: Fri, 29 Sep 2023 15:46:43 +0200 Subject: [PATCH] update anchor when requesting secure status --- .../notary/OfficeFolderAnchorsController.ts | 29 +++++++++++++++++-- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/src/app/api/notary/OfficeFolderAnchorsController.ts b/src/app/api/notary/OfficeFolderAnchorsController.ts index bc14dadb..9c4c7fdf 100644 --- a/src/app/api/notary/OfficeFolderAnchorsController.ts +++ b/src/app/api/notary/OfficeFolderAnchorsController.ts @@ -174,9 +174,10 @@ export default class OfficeFoldersController extends ApiController { files: true, }, }, + folder_anchor: true, }; - const officeFolderFound = await this.officeFoldersService.getByUid(uid, query); + const officeFolderFound: any = await this.officeFoldersService.getByUid(uid, query); if (!officeFolderFound) { this.httpNotFoundRequest(response, "Office folder not found"); @@ -192,9 +193,31 @@ export default class OfficeFoldersController extends ApiController { } const sortedHashes = [...folderHashes].sort(); - const anchor = await this.secureService.verify(sortedHashes); + const officeFolderAnchorFound = OfficeFolderAnchor.hydrate(officeFolderFound.folder_anchor, { + strategy: "excludeAll", + }); - this.httpSuccess(response, anchor); + if (!officeFolderAnchorFound || !officeFolderAnchorFound.uid) { + 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}); + return; + } + + const officeFolderAnchor = hydrateOfficeFolderAnchor(data); + + const updatedOfficeFolderAnchor = await this.officeFolderAnchorsRepository.update( + officeFolderAnchorFound.uid, + officeFolderAnchor + ); + + this.httpSuccess(response, updatedOfficeFolderAnchor); + return; } catch (error) { this.httpInternalError(response, error); return;