send anchoring notification

This commit is contained in:
Loïs Mansot 2023-09-29 18:47:43 +02:00
parent 6d4d4f05e5
commit f99612a85d
No known key found for this signature in database
GPG Key ID: 8CF1F4150DDA726D
2 changed files with 16 additions and 9 deletions

View File

@ -53,7 +53,7 @@
"express": "^4.18.2", "express": "^4.18.2",
"fp-ts": "^2.16.1", "fp-ts": "^2.16.1",
"jsonwebtoken": "^9.0.0", "jsonwebtoken": "^9.0.0",
"le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.86", "le-coffre-resources": "git@github.com:smart-chain-fr/leCoffre-resources.git#v2.87",
"module-alias": "^2.2.2", "module-alias": "^2.2.2",
"monocle-ts": "^2.3.13", "monocle-ts": "^2.3.13",
"multer": "^1.4.5-lts.1", "multer": "^1.4.5-lts.1",

View File

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