update anchor when requesting secure status

This commit is contained in:
Loïs Mansot 2023-09-29 15:46:43 +02:00
parent ab4fac8e01
commit 279ea66a50
No known key found for this signature in database
GPG Key ID: 8CF1F4150DDA726D

View File

@ -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<OfficeFolderAnchor>(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;