send anchoring notification (#107)
This commit is contained in:
commit
9725eed815
@ -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) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user