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 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,
@ -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) {