This repository has been archived by the owner on Feb 8, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
decision.service.js
91 lines (77 loc) · 2.33 KB
/
decision.service.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import signingService from "./signing.service";
import queryService from "./query.service";
import decisionHelper from "../utils/helpers/decision.helper";
import logger from "../config/Log";
const Publish = async resource => {
try {
// GET USERID OUT OF RESOURCE
const { content, resourceId, oit, timestamp, subject, version } = resource;
const mockLimitedSigners = 2;
// TODO express-validation
if (!content || !resourceId || !oit || !timestamp || !subject) {
throw new Error("Predefined resource model expectation was not met!");
}
const user = await decisionHelper.getUser(oit);
// SIGN TRANSACTION
const args = {
id: resourceId,
hash: content,
subject,
timestamp,
version,
limitedSigners: mockLimitedSigners
};
const result = await signingService.SignTransaction(
args,
user,
"publishResource" // TODO don't hardcode
);
logger.info("Resource was succesfully published to the blockchain!");
return result;
} catch (e) {
logger.info(`Something went wrong in decision.service.js: ${e}`);
throw new Error(e);
}
};
const Sign = async resource => {
try {
// GET USERID OUT OF RESOURCE
const { content, resourceId, oit, timestamp, subject, version } = resource;
const mockLimitedSigners = 2;
const user = await decisionHelper.getUser(oit);
// SIGN TRANSACTION
const args = {
id: resourceId,
hash: content,
timestamp,
limitedSigners: mockLimitedSigners,
subject,
version
};
const result = await signingService.SignTransaction(
args,
user,
"signResource" // TODO don't hardcode
);
logger.info("Resource was succesfully published to the blockchain!");
return result;
} catch (e) {
logger.info(`Something went wrong: ${e}`);
throw new Error(e);
}
};
const GetResourceHistory = id => queryService.GetResourceHistory(id);
const GetResourceHistoryByVersion = (id, version) =>
queryService.GetResourceHistoryByVersion(id, version);
const Validate = (id, hash) => queryService.Validate(id, hash);
const GetAll = () => queryService.GetAll();
const GetResourceById = id => queryService.GetResourceById(id);
export default {
Publish,
Sign,
Validate,
GetAll,
GetResourceById,
GetResourceHistory,
GetResourceHistoryByVersion
};