@getjones/test-infra 2.3.0 → 2.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -1
- package/src/common/utils/objectUtils.js +9 -0
- package/src/common/utils/timeUtils.js +5 -1
- package/src/defaults/configs/auditConfigs.js +85 -0
- package/src/defaults/configs/polices.js +47 -0
- package/src/defaults/configs/requirement.js +29 -0
- package/src/defaults/index.js +5 -0
- package/src/env.js +13 -1
- package/src/index.js +2 -0
- package/src/saas/internal-api/auth/api/auth.service.js +10 -18
- package/src/saas/internal-api/compliance/api/audit/audit.api.js +0 -1
- package/src/saas/internal-api/compliance/utils/util.js +7 -5
- package/src/saas/internal-api/requirements/api/requirements.api.js +20 -3
- package/src/saas/internal-api/requirements/api/requirements.service.js +29 -9
- package/src/saas/internal-api/requirements/consts/consts.js +6 -0
- package/src/saas/internal-api/requirements/index.js +3 -1
- package/src/saas/internal-api/requirements/models/create.requirement.model.js +6 -35
- package/src/saas/internal-api/requirements/models/policy.model.js +32 -0
- package/src/saas/internal-api/requirements/models/update.requirement.model.js +21 -0
- package/src/saas/internal-api/requirements/utils/utils.js +25 -12
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@getjones/test-infra",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"description": "Providing internal and openapi interface",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
"chai": "^4.3.4",
|
|
16
16
|
"dotenv": "^8.2.0",
|
|
17
17
|
"enum": "^3.0.4",
|
|
18
|
+
"lodash": "^4.17.21",
|
|
18
19
|
"mocha": "^8.3.2"
|
|
19
20
|
},
|
|
20
21
|
"devDependencies": {
|
|
@@ -36,6 +36,8 @@ const getDateInOneDay = format => moment().utc().add(1, peroids.days).format(for
|
|
|
36
36
|
const getDateinSixDays = format => moment().utc().add(6, peroids.days).format(format || formats.threadScheduler);
|
|
37
37
|
const getDateinThirteenDays = format => moment().utc().add(13, peroids.days).format(format || formats.threadScheduler);
|
|
38
38
|
const getDateinTwentyNineDays = format => moment().utc().add(29, peroids.days).format(format || formats.threadScheduler);
|
|
39
|
+
const getOneWeekAgoDate = format => moment().utc().subtract(7, peroids.days).format(format || formats.threadScheduler);
|
|
40
|
+
const getOneWeekAheadDate = format => moment().utc().add(7, peroids.days).format(format || formats.threadScheduler);
|
|
39
41
|
|
|
40
42
|
const getLogTimestamp = () => {
|
|
41
43
|
return moment().format(formats.logTimeStampFormat);
|
|
@@ -163,5 +165,7 @@ module.exports = {
|
|
|
163
165
|
getPreviousDateByDays,
|
|
164
166
|
waitFor,
|
|
165
167
|
isDateAfterOther,
|
|
166
|
-
convertDateToNewFormat
|
|
168
|
+
convertDateToNewFormat,
|
|
169
|
+
getOneWeekAgoDate,
|
|
170
|
+
getOneWeekAheadDate
|
|
167
171
|
};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
const { policyNames, attributeNames } = require('./polices');
|
|
2
|
+
const { cloneObject } = require('../../common/utils/objectUtils');
|
|
3
|
+
const { getOneWeekAgoDate, getOneWeekAheadDate } = require('../../common/utils/timeUtils');
|
|
4
|
+
|
|
5
|
+
const DEFAULT_POLICY_DATE = '24/05/2030';
|
|
6
|
+
const DEFAULT_AM_SCORE = 'A';
|
|
7
|
+
const DEFAULT_POLICY_NUMBER = '12345';
|
|
8
|
+
|
|
9
|
+
const {
|
|
10
|
+
certificateIssueDate,
|
|
11
|
+
generalLiability
|
|
12
|
+
} = policyNames;
|
|
13
|
+
|
|
14
|
+
const {
|
|
15
|
+
coverageExists,
|
|
16
|
+
policyNumber,
|
|
17
|
+
policyExpired,
|
|
18
|
+
perOccurrence,
|
|
19
|
+
perPolicy,
|
|
20
|
+
perProject,
|
|
21
|
+
perLocation,
|
|
22
|
+
eachOccurrence,
|
|
23
|
+
cancellationTerms,
|
|
24
|
+
coiAuthentication,
|
|
25
|
+
signature,
|
|
26
|
+
amScore,
|
|
27
|
+
insuredAddress,
|
|
28
|
+
insuredName
|
|
29
|
+
} = attributeNames;
|
|
30
|
+
|
|
31
|
+
const policySelections = {
|
|
32
|
+
YES: 'Yes',
|
|
33
|
+
NO: 'No',
|
|
34
|
+
OTHER: 'Other'
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getCompliantAuditConfig = ({ glPolicyNumber = DEFAULT_POLICY_NUMBER } = {}) => {
|
|
38
|
+
return cloneObject({
|
|
39
|
+
[certificateIssueDate]: DEFAULT_POLICY_DATE,
|
|
40
|
+
[insuredAddress]: policySelections.YES,
|
|
41
|
+
[insuredName]: policySelections.YES,
|
|
42
|
+
[amScore]: DEFAULT_AM_SCORE,
|
|
43
|
+
[generalLiability]: {
|
|
44
|
+
[coverageExists]: policySelections.YES,
|
|
45
|
+
[policyNumber]: glPolicyNumber,
|
|
46
|
+
[policyExpired]: DEFAULT_POLICY_DATE,
|
|
47
|
+
[perOccurrence]: policySelections.YES,
|
|
48
|
+
[perPolicy]: policySelections.YES,
|
|
49
|
+
[perProject]: policySelections.YES,
|
|
50
|
+
[perLocation]: policySelections.YES,
|
|
51
|
+
[eachOccurrence]: policySelections.YES
|
|
52
|
+
},
|
|
53
|
+
[cancellationTerms]: policySelections.YES,
|
|
54
|
+
[coiAuthentication]: policySelections.YES,
|
|
55
|
+
[signature]: policySelections.YES
|
|
56
|
+
});
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
const getNotCompliantConfig = ({ glPolicyNumber } = {}) => {
|
|
60
|
+
const compliantConfig = getCompliantAuditConfig({ glPolicyNumber });
|
|
61
|
+
compliantConfig[signature] = policySelections.NO;
|
|
62
|
+
|
|
63
|
+
return compliantConfig;
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
const getAboutExpiredConfig = ({ glPolicyNumber } = {}) => {
|
|
67
|
+
const compliantConfig = getCompliantAuditConfig({ glPolicyNumber });
|
|
68
|
+
compliantConfig[generalLiability][policyExpired] = getOneWeekAheadDate();
|
|
69
|
+
|
|
70
|
+
return compliantConfig;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
const getExpiredConfig = ({ glPolicyNumber } = {}) => {
|
|
74
|
+
const compliantConfig = getCompliantAuditConfig({ glPolicyNumber });
|
|
75
|
+
compliantConfig[generalLiability][policyExpired] = getOneWeekAgoDate();
|
|
76
|
+
|
|
77
|
+
return compliantConfig;
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
module.exports = {
|
|
81
|
+
getCompliantAuditConfig,
|
|
82
|
+
getNotCompliantConfig,
|
|
83
|
+
getAboutExpiredConfig,
|
|
84
|
+
getExpiredConfig
|
|
85
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const policyNames = {
|
|
2
|
+
certificateOfInsurance: 'Certificate of Insurance',
|
|
3
|
+
certificateIssueDate: 'Certificate issue date',
|
|
4
|
+
generalLiability: 'General Liability',
|
|
5
|
+
excessLiability: 'Excess Liability',
|
|
6
|
+
umbrella: 'Umbrella',
|
|
7
|
+
professionalLiability: 'Professional Liability',
|
|
8
|
+
environmentalLiability: 'Environmental Liability',
|
|
9
|
+
liquorLiability: 'Liquor Liability',
|
|
10
|
+
garageLiability: 'Garage Liability',
|
|
11
|
+
garageKeepersLiability: 'Garage Keepers Liability',
|
|
12
|
+
workersCompensation: 'Workers’ Compensation',
|
|
13
|
+
automobileLiability: 'Automobile Liability',
|
|
14
|
+
propertyInsurance: 'Property Insurance',
|
|
15
|
+
rentedLeasedEquipment: 'Rented/Leased Equipment',
|
|
16
|
+
fidelityCrime: 'Fidelity / Crime',
|
|
17
|
+
employmentPracticesLiability: 'Employment Practices Liability',
|
|
18
|
+
directorsAndOfficersLiability: 'Directors and Officers Liability',
|
|
19
|
+
cyberLiability: 'Cyber Liability',
|
|
20
|
+
waiverOfSubrogation: 'Waiver Of Subrogation',
|
|
21
|
+
agreement: 'Agreement',
|
|
22
|
+
certificateHolder: 'Certificate Holder',
|
|
23
|
+
additionalInformation: 'Additional Information',
|
|
24
|
+
additionalInsured: 'Additional Insured'
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const attributeNames = {
|
|
28
|
+
insuredAddress: 'Insured Address',
|
|
29
|
+
insuredName: 'Insured Name',
|
|
30
|
+
amScore: 'AM Score',
|
|
31
|
+
coverageExists: 'Coverage Exists',
|
|
32
|
+
eachOccurrence: 'Each Occurrence',
|
|
33
|
+
policyNumber: 'Policy Number',
|
|
34
|
+
policyExpired: 'Policy Expiry',
|
|
35
|
+
perPolicy: 'Per Policy',
|
|
36
|
+
perProject: 'Per Project',
|
|
37
|
+
perLocation: 'Per Location',
|
|
38
|
+
perOccurrence: 'Per Occur',
|
|
39
|
+
cancellationTerms: 'Cancellation Terms',
|
|
40
|
+
coiAuthentication: 'COI authentication',
|
|
41
|
+
signature: 'Signature'
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
policyNames,
|
|
46
|
+
attributeNames
|
|
47
|
+
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
const { policyNames, attributeNames } = require('../configs/polices');
|
|
2
|
+
const { cloneObject } = require('../../common/utils/objectUtils');
|
|
3
|
+
|
|
4
|
+
const { eachOccurrence } = attributeNames;
|
|
5
|
+
const { generalLiability } = policyNames;
|
|
6
|
+
|
|
7
|
+
const DEFAULT_REQUIREMENT_NAME = 'Integration Requirement';
|
|
8
|
+
const DEFAULT_COVERAGE_VALUE = 1000000;
|
|
9
|
+
|
|
10
|
+
const getDefaultRequirementPolices = () => {
|
|
11
|
+
return cloneObject({
|
|
12
|
+
[generalLiability]: {
|
|
13
|
+
[eachOccurrence]: DEFAULT_COVERAGE_VALUE
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
const defaultRequirementConfig = () => {
|
|
19
|
+
return {
|
|
20
|
+
name: DEFAULT_REQUIREMENT_NAME,
|
|
21
|
+
policies: getDefaultRequirementPolices()
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
module.exports = {
|
|
26
|
+
name: DEFAULT_REQUIREMENT_NAME,
|
|
27
|
+
getDefaultRequirementPolices,
|
|
28
|
+
defaultRequirementConfig
|
|
29
|
+
};
|
package/src/env.js
CHANGED
|
@@ -37,9 +37,21 @@ const isLocalhost = () => {
|
|
|
37
37
|
return privateMembers.backendUrl.includes('localhost');
|
|
38
38
|
};
|
|
39
39
|
|
|
40
|
+
const systemUserIdentities = {};
|
|
41
|
+
|
|
42
|
+
const getSystemUserIdentity = email => {
|
|
43
|
+
return systemUserIdentities[email] || null;
|
|
44
|
+
};
|
|
45
|
+
|
|
46
|
+
const addUserIdentity = (email, cookie, id) => {
|
|
47
|
+
systemUserIdentities[email] = { cookie, id };
|
|
48
|
+
};
|
|
49
|
+
|
|
40
50
|
module.exports = {
|
|
41
51
|
init,
|
|
42
52
|
getEnv: () => privateMembers,
|
|
43
53
|
requiredValidation,
|
|
44
|
-
isLocalhost
|
|
54
|
+
isLocalhost,
|
|
55
|
+
getSystemUserIdentity,
|
|
56
|
+
addUserIdentity
|
|
45
57
|
};
|
package/src/index.js
CHANGED
|
@@ -9,6 +9,7 @@ const init = conf => {
|
|
|
9
9
|
};
|
|
10
10
|
|
|
11
11
|
const getInternalAPI = () => {
|
|
12
|
+
const defaults = require('./defaults');
|
|
12
13
|
const auth = require('./saas/internal-api/auth');
|
|
13
14
|
const accounts = require('./saas/internal-api/accounts');
|
|
14
15
|
|
|
@@ -35,6 +36,7 @@ const getInternalAPI = () => {
|
|
|
35
36
|
const dbEmails = require('./saas/internal-api/dbEmails/index');
|
|
36
37
|
|
|
37
38
|
const internalAPI = {
|
|
39
|
+
defaults,
|
|
38
40
|
auth,
|
|
39
41
|
accounts,
|
|
40
42
|
projects,
|
|
@@ -1,12 +1,20 @@
|
|
|
1
|
-
const { getEnv, requiredValidation } = require('../../../../env');
|
|
1
|
+
const { getEnv, requiredValidation, getSystemUserIdentity, addUserIdentity } = require('../../../../env');
|
|
2
2
|
const { credentials } = getEnv();
|
|
3
3
|
const authApi = require('./auth.api');
|
|
4
4
|
|
|
5
5
|
const getAuthCookie = async (email, password) => {
|
|
6
|
+
const systemUser = getSystemUserIdentity(email);
|
|
7
|
+
|
|
8
|
+
if (systemUser) {
|
|
9
|
+
return systemUser.cookie;
|
|
10
|
+
}
|
|
11
|
+
|
|
6
12
|
try {
|
|
7
13
|
const response = await authApi.login(email, password);
|
|
8
14
|
const authCookie = response.headers['set-cookie'].find(item => item.startsWith('JonesToken='));
|
|
9
15
|
|
|
16
|
+
addUserIdentity(email, authCookie, response.data.id);
|
|
17
|
+
|
|
10
18
|
return authCookie;
|
|
11
19
|
} catch (error) {
|
|
12
20
|
throw new Error(`Failed to login to email:${email}`, error);
|
|
@@ -50,26 +58,10 @@ const getOperatorCookie = () => {
|
|
|
50
58
|
return getAuthCookie(operatorUser, operatorPassword);
|
|
51
59
|
};
|
|
52
60
|
|
|
53
|
-
const getAuditorId = async () => {
|
|
54
|
-
const { auditorUser, auditorPassword } = credentials;
|
|
55
|
-
requiredValidation({
|
|
56
|
-
'credentials.auditorUser': auditorUser,
|
|
57
|
-
'credentials.auditorPassword': auditorPassword
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
try {
|
|
61
|
-
const response = await authApi.login(auditorUser, auditorPassword);
|
|
62
|
-
return response.data.id;
|
|
63
|
-
} catch (error) {
|
|
64
|
-
throw new Error('Failed to get auditor id', error);
|
|
65
|
-
}
|
|
66
|
-
};
|
|
67
|
-
|
|
68
61
|
module.exports = {
|
|
69
62
|
getAuthCookie,
|
|
70
63
|
getVendorHubAuthCookie,
|
|
71
64
|
getIcsCookie,
|
|
72
65
|
getAuditorCookie,
|
|
73
|
-
getOperatorCookie
|
|
74
|
-
getAuditorId
|
|
66
|
+
getOperatorCookie
|
|
75
67
|
};
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
2
|
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
|
-
const { createAuditEntity } = require('../../utils/util');
|
|
4
3
|
|
|
5
4
|
const Endpoints = {
|
|
6
5
|
auditorContractorList: `${backendUrl}/saas/auditor/contractors`,
|
|
@@ -2,7 +2,8 @@ const { AUDIT_ENTITY_STATUSES, DEFAULT_POLICY_ID, VALID_SCORES } = require('../c
|
|
|
2
2
|
const { isObject, isArray } = require('../../../../common/utils/dataTypeUtils');
|
|
3
3
|
const timeUtils = require('../../../../common/utils/timeUtils');
|
|
4
4
|
const auditModels = require('../models/audit/audit.model');
|
|
5
|
-
const
|
|
5
|
+
const { getEnv, getSystemUserIdentity } = require('../../../../env');
|
|
6
|
+
const { credentials } = getEnv();
|
|
6
7
|
|
|
7
8
|
const emptyValue = '';
|
|
8
9
|
|
|
@@ -67,7 +68,7 @@ const getParsedConfig = function(config) {
|
|
|
67
68
|
}
|
|
68
69
|
|
|
69
70
|
if (isArray(attributes[attributeName])) {
|
|
70
|
-
selection.status = AUDIT_ENTITY_STATUSES[ attributes[attributeName][0] ];
|
|
71
|
+
selection.status = AUDIT_ENTITY_STATUSES[ (attributes[attributeName][0]).toUpperCase() ];
|
|
71
72
|
selection.value = attributes[attributeName][1].replace('$', emptyValue);
|
|
72
73
|
} else {
|
|
73
74
|
// Special statuses switch
|
|
@@ -97,10 +98,10 @@ const getParsedConfig = function(config) {
|
|
|
97
98
|
certificateEndorsmentsList.includes(field) && (selection.policyName = field);
|
|
98
99
|
|
|
99
100
|
if (isArray(config[field])) {
|
|
100
|
-
selection.status = AUDIT_ENTITY_STATUSES[ config[field][0] ];
|
|
101
|
+
selection.status = AUDIT_ENTITY_STATUSES[ (config[field][0]).toUpperCase() ];
|
|
101
102
|
selection.value = config[field][1]; // Ok to be undefined
|
|
102
103
|
} else {
|
|
103
|
-
selection.status = AUDIT_ENTITY_STATUSES[ config[field] ] || AUDIT_ENTITY_STATUSES.YES;
|
|
104
|
+
selection.status = AUDIT_ENTITY_STATUSES[ (config[field]).toUpperCase() ] || AUDIT_ENTITY_STATUSES.YES;
|
|
104
105
|
selection.value = getValueBySelection(config[field]);
|
|
105
106
|
}
|
|
106
107
|
|
|
@@ -127,7 +128,8 @@ const createAuditEntity = (
|
|
|
127
128
|
};
|
|
128
129
|
|
|
129
130
|
const getAuditorId = () => {
|
|
130
|
-
|
|
131
|
+
const auditorIdentity = getSystemUserIdentity(credentials.auditorUser);
|
|
132
|
+
return auditorIdentity.id;
|
|
131
133
|
};
|
|
132
134
|
|
|
133
135
|
module.exports = {
|
|
@@ -5,6 +5,8 @@ const Endpoints = {
|
|
|
5
5
|
create: `${backendUrl}/saas/requirement`,
|
|
6
6
|
getRequirementsByTabId: `${backendUrl}/saas/requirements`,
|
|
7
7
|
getRequirementById: requirementId => `${backendUrl}/saas/requirement/${requirementId}`,
|
|
8
|
+
update: `${backendUrl}/saas/requirement/linked/edit`,
|
|
9
|
+
updateWithNotification: `${backendUrl}/saas/requirement/linked/edit/notify`,
|
|
8
10
|
delete: requirementId => `${backendUrl}/saas/requirement/${requirementId}`
|
|
9
11
|
};
|
|
10
12
|
|
|
@@ -17,12 +19,27 @@ const getRequirementsByTabId = (tabId, context) => {
|
|
|
17
19
|
return requests.getRequestHandler(Endpoints.getRequirementsByTabId, { tabId }, context);
|
|
18
20
|
};
|
|
19
21
|
|
|
20
|
-
const getRequirementById = (requirementId, context) => {
|
|
21
|
-
return requests.getRequestHandler(Endpoints.getRequirementById(requirementId), {}, context);
|
|
22
|
+
const getRequirementById = (requirementId, context, isPermanentLink = false) => {
|
|
23
|
+
return requests.getRequestHandler(Endpoints.getRequirementById(requirementId), { isPermanentLink }, context);
|
|
24
|
+
};
|
|
25
|
+
|
|
26
|
+
const updateRequirement = (updateRequirementModel, tabId, context) => {
|
|
27
|
+
return requests.postRequestHandler(Endpoints.update, updateRequirementModel, context, {}, { tabId });
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const updateRequirementWithNotification = (updateRequirementModel, context) => {
|
|
31
|
+
return requests.postRequestHandler(Endpoints.updateWithNotification, updateRequirementModel, context);
|
|
22
32
|
};
|
|
23
33
|
|
|
24
34
|
const deleteByRequirementId = (requirementId, context) => {
|
|
25
35
|
return requests.deleteRequestHandler(Endpoints.delete(requirementId), context);
|
|
26
36
|
};
|
|
27
37
|
|
|
28
|
-
module.exports = {
|
|
38
|
+
module.exports = {
|
|
39
|
+
createRequirement,
|
|
40
|
+
getRequirementsByTabId,
|
|
41
|
+
getRequirementById,
|
|
42
|
+
updateRequirement,
|
|
43
|
+
updateRequirementWithNotification,
|
|
44
|
+
deleteByRequirementId
|
|
45
|
+
};
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
const requirementsAPI = require('./requirements.api');
|
|
2
2
|
const { CreateRequirementModel } = require('../models/create.requirement.model');
|
|
3
|
+
const { UpdateRequirementModel } = require('../models/update.requirement.model');
|
|
3
4
|
const requirementUtils = require('../utils/utils');
|
|
4
5
|
|
|
5
6
|
const { validateType } = require('../../../../common/validations/typeValidations');
|
|
@@ -13,11 +14,11 @@ const getRequirementsByTabId = (tabId, context) => {
|
|
|
13
14
|
return requirementsAPI.getRequirementsByTabId(tabId, context);
|
|
14
15
|
};
|
|
15
16
|
|
|
16
|
-
const getRequirementById = (requirementId, context) => {
|
|
17
|
-
return requirementsAPI.getRequirementById(requirementId, context);
|
|
17
|
+
const getRequirementById = (requirementId, context, isPermanentLink = false) => {
|
|
18
|
+
return requirementsAPI.getRequirementById(requirementId, context, isPermanentLink);
|
|
18
19
|
};
|
|
19
20
|
|
|
20
|
-
const getRequirementByName = async (tabId, requirementName, context) => {
|
|
21
|
+
const getRequirementByName = async (tabId, requirementName, context, isPermanentLink = false) => {
|
|
21
22
|
const { data: requirementList } = await getRequirementsByTabId(tabId, context);
|
|
22
23
|
|
|
23
24
|
const requirement = requirementList.find(req => req.name === requirementName);
|
|
@@ -26,7 +27,7 @@ const getRequirementByName = async (tabId, requirementName, context) => {
|
|
|
26
27
|
return null;
|
|
27
28
|
}
|
|
28
29
|
|
|
29
|
-
const requirementResponse = await getRequirementById(requirement.id, context);
|
|
30
|
+
const requirementResponse = await getRequirementById(requirement.id, context, isPermanentLink);
|
|
30
31
|
return requirementResponse.data.requirement;
|
|
31
32
|
};
|
|
32
33
|
|
|
@@ -39,7 +40,7 @@ const getOrCreateRequirement = async (requirement, tabId, context) => {
|
|
|
39
40
|
let existingRequirement = await getRequirementByName(tabId, requirement.name, context);
|
|
40
41
|
|
|
41
42
|
if (!existingRequirement) {
|
|
42
|
-
const createRequirementModel = getCreateRequirementModel(requirement
|
|
43
|
+
const createRequirementModel = getCreateRequirementModel(requirement);
|
|
43
44
|
await createRequirement(createRequirementModel, tabId, context);
|
|
44
45
|
existingRequirement = await getRequirementByName(tabId, requirement.name, context);
|
|
45
46
|
}
|
|
@@ -47,6 +48,16 @@ const getOrCreateRequirement = async (requirement, tabId, context) => {
|
|
|
47
48
|
return existingRequirement;
|
|
48
49
|
};
|
|
49
50
|
|
|
51
|
+
const updateRequirement = (updateRequirementModel, tabId, context) => {
|
|
52
|
+
validateType(updateRequirementModel, UpdateRequirementModel);
|
|
53
|
+
return requirementsAPI.updateRequirement(updateRequirementModel, tabId, context);
|
|
54
|
+
};
|
|
55
|
+
|
|
56
|
+
const updateRequirementWithNotification = (updateRequirementModel, context) => {
|
|
57
|
+
validateType(updateRequirementModel, UpdateRequirementModel);
|
|
58
|
+
return requirementsAPI.updateRequirementWithNotification(updateRequirementModel, context);
|
|
59
|
+
};
|
|
60
|
+
|
|
50
61
|
const deleteByRequirementId = (requirementId, context) => {
|
|
51
62
|
return requirementsAPI.deleteByRequirementId(requirementId, context);
|
|
52
63
|
};
|
|
@@ -56,8 +67,15 @@ const deleteRequirementByName = async (requirementName, tabId, context) => {
|
|
|
56
67
|
return deleteByRequirementId(requirementToDelete.id, context);
|
|
57
68
|
};
|
|
58
69
|
|
|
59
|
-
const getCreateRequirementModel =
|
|
60
|
-
return requirementUtils.getCreateRequirementModel(
|
|
70
|
+
const getCreateRequirementModel = requirement => {
|
|
71
|
+
return requirementUtils.getCreateRequirementModel(requirement);
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
const getUpdatedRequirementModel = async (requirementId, requirementPolicies, requirementName, accountId, projectId, tabId, context) => {
|
|
75
|
+
const getRequirementData = await getRequirementByName(tabId, requirementName, context);
|
|
76
|
+
const dateModified = getRequirementData.dateModified;
|
|
77
|
+
|
|
78
|
+
return requirementUtils.getUpdateRequirementModel(requirementId, requirementPolicies, requirementName, accountId, projectId, tabId, dateModified);
|
|
61
79
|
};
|
|
62
80
|
|
|
63
81
|
module.exports = {
|
|
@@ -67,8 +85,10 @@ module.exports = {
|
|
|
67
85
|
getRequirementIdByName,
|
|
68
86
|
getRequirementsByTabId,
|
|
69
87
|
getOrCreateRequirement,
|
|
88
|
+
updateRequirement,
|
|
89
|
+
updateRequirementWithNotification,
|
|
70
90
|
deleteByRequirementId,
|
|
71
91
|
deleteRequirementByName,
|
|
72
|
-
|
|
73
|
-
|
|
92
|
+
getCreateRequirementModel,
|
|
93
|
+
getUpdatedRequirementModel
|
|
74
94
|
};
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
const createModel = require('./models/create.requirement.model');
|
|
2
|
+
const updateModel = require('./models/update.requirement.model');
|
|
3
|
+
const policyModel = require('./models/policy.model');
|
|
2
4
|
const services = require('./api/requirements.service');
|
|
3
5
|
|
|
4
|
-
const models = { create: createModel };
|
|
6
|
+
const models = { create: createModel, update: updateModel, policy: policyModel };
|
|
5
7
|
|
|
6
8
|
module.exports = { services, models };
|
|
@@ -1,46 +1,17 @@
|
|
|
1
|
-
const Enum = require('enum');
|
|
2
1
|
const { validateType } = require('../../../../common/validations/typeValidations');
|
|
2
|
+
const { PolicyModel } = require('./policy.model');
|
|
3
3
|
|
|
4
|
-
const
|
|
4
|
+
const { REQUIREMENT_SHARING_LEVELS } = require('../consts/consts');
|
|
5
5
|
|
|
6
6
|
class CreateRequirementModel {
|
|
7
|
-
constructor(name, policies) {
|
|
7
|
+
constructor(name, policies, sharingLevel = REQUIREMENT_SHARING_LEVELS.TAB) {
|
|
8
8
|
this.name = name;
|
|
9
9
|
this.policies = policies;
|
|
10
|
-
this.
|
|
10
|
+
this.sharingLevel = sharingLevel;
|
|
11
11
|
|
|
12
12
|
validateType(policies, Array);
|
|
13
|
-
policies && validateType(policies[0],
|
|
13
|
+
policies && validateType(policies[0], PolicyModel);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
|
|
17
|
-
|
|
18
|
-
constructor(name, attributes) {
|
|
19
|
-
this.policyName = name;
|
|
20
|
-
this.attributes = attributes;
|
|
21
|
-
|
|
22
|
-
validateType(attributes, Array);
|
|
23
|
-
attributes && validateType(attributes[0], Attribute);
|
|
24
|
-
}
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
class Attribute {
|
|
28
|
-
constructor(name, type, values) {
|
|
29
|
-
this.attributeName = name;
|
|
30
|
-
this.type = type.value;
|
|
31
|
-
this.values = values.map(value => ({ value }));
|
|
32
|
-
|
|
33
|
-
if (!AttributeTypes.get(type) || !AttributeTypes.get(type.key)) {
|
|
34
|
-
throw TypeError(`Expected type to be instance of: ${AttributeTypes.name}`);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
const AttributeTypes = new Enum({
|
|
40
|
-
'ENDORSMENT': 'endorsment',
|
|
41
|
-
'LIMIT': 'limit',
|
|
42
|
-
'BOOLEAN': 'boolean',
|
|
43
|
-
'MULTIPLE': 'multiple'
|
|
44
|
-
}, { name: 'AttributeTypes' });
|
|
45
|
-
|
|
46
|
-
module.exports = { CreateRequirementModel, Policy, Attribute, AttributeTypes };
|
|
17
|
+
module.exports = { CreateRequirementModel };
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const Enum = require('enum');
|
|
2
|
+
const { validateType } = require('../../../../common/validations/typeValidations');
|
|
3
|
+
|
|
4
|
+
class PolicyModel {
|
|
5
|
+
constructor(name, attributes) {
|
|
6
|
+
this.policyName = name;
|
|
7
|
+
this.attributes = attributes;
|
|
8
|
+
validateType(attributes, Array);
|
|
9
|
+
attributes && validateType(attributes[0], AttributeModel);
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
class AttributeModel {
|
|
14
|
+
constructor(name, type, values) {
|
|
15
|
+
this.attributeName = name;
|
|
16
|
+
this.type = type.value;
|
|
17
|
+
this.values = values.map(value => ({ value }));
|
|
18
|
+
|
|
19
|
+
if (!AttributeTypes.get(type) || !AttributeTypes.get(type.key)) {
|
|
20
|
+
throw TypeError(`Expected type to be instance of: ${AttributeTypes.name}`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
const AttributeTypes = new Enum({
|
|
26
|
+
'ENDORSMENT': 'endorsment',
|
|
27
|
+
'LIMIT': 'limit',
|
|
28
|
+
'BOOLEAN': 'boolean',
|
|
29
|
+
'MULTIPLE': 'multiple'
|
|
30
|
+
}, { name: 'AttributeTypes' });
|
|
31
|
+
|
|
32
|
+
module.exports = { PolicyModel, AttributeModel, AttributeTypes };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const { validateType } = require('../../../../common/validations/typeValidations');
|
|
2
|
+
const { PolicyModel } = require('./policy.model');
|
|
3
|
+
const DEFAULT_REQUIREMENT_TYPE = 'REQUIREMENT';
|
|
4
|
+
|
|
5
|
+
class UpdateRequirementModel {
|
|
6
|
+
constructor(id, accountId, projectId, tabId, name, policies, dateModified) {
|
|
7
|
+
this.id = id;
|
|
8
|
+
this.userId = accountId;
|
|
9
|
+
this.projectId = projectId;
|
|
10
|
+
this.tabId = tabId;
|
|
11
|
+
this.name = name;
|
|
12
|
+
this.policies = policies;
|
|
13
|
+
this.requirementType = DEFAULT_REQUIREMENT_TYPE;
|
|
14
|
+
this.dateModified = dateModified;
|
|
15
|
+
|
|
16
|
+
validateType(policies, Array);
|
|
17
|
+
policies && validateType(policies[0], PolicyModel);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = { UpdateRequirementModel };
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
const models = require('../models/create.requirement.model');
|
|
2
1
|
const attributeTypes = require('../consts/attributeTypes.json');
|
|
3
2
|
const dataTypeUtils = require('../../../../common/utils/dataTypeUtils');
|
|
3
|
+
const { UpdateRequirementModel } = require('../models/update.requirement.model');
|
|
4
|
+
const { AttributeModel, PolicyModel, AttributeTypes } = require('../models/policy.model');
|
|
5
|
+
const { CreateRequirementModel } = require('../models/create.requirement.model');
|
|
6
|
+
const { REQUIREMENT_SHARING_LEVELS } = require('../consts/consts');
|
|
4
7
|
|
|
5
8
|
const convertNumericValuesToNumberType = function(value) {
|
|
6
9
|
if (dataTypeUtils.isString(value) && value.startsWith('$')) {
|
|
@@ -14,22 +17,22 @@ const preparePolicyAttributesTypes = function(value) {
|
|
|
14
17
|
const attributesValue = convertNumericValuesToNumberType(value);
|
|
15
18
|
|
|
16
19
|
if (dataTypeUtils.isNumber(attributesValue)) {
|
|
17
|
-
return
|
|
20
|
+
return AttributeTypes.get(attributeTypes.limit);
|
|
18
21
|
}
|
|
19
22
|
|
|
20
23
|
if (dataTypeUtils.isBoolean(attributesValue)) {
|
|
21
|
-
return
|
|
24
|
+
return AttributeTypes.get(attributeTypes.boolean);
|
|
22
25
|
}
|
|
23
26
|
|
|
24
|
-
return
|
|
27
|
+
return AttributeTypes.get(attributeTypes.multiple);
|
|
25
28
|
};
|
|
26
29
|
|
|
27
30
|
const prepareEndorsmentAttributesTypes = function(value) {
|
|
28
31
|
if (dataTypeUtils.isBoolean(value)) {
|
|
29
|
-
return
|
|
32
|
+
return AttributeTypes.get(attributeTypes.boolean);
|
|
30
33
|
}
|
|
31
34
|
|
|
32
|
-
return
|
|
35
|
+
return AttributeTypes.get(attributeTypes.endorsment);
|
|
33
36
|
};
|
|
34
37
|
|
|
35
38
|
const parseRequirementConfig = function(config) {
|
|
@@ -71,18 +74,28 @@ const parseRequirementConfig = function(config) {
|
|
|
71
74
|
const getPolicyModel = function(policyData) {
|
|
72
75
|
const attributes = policyData.attributes;
|
|
73
76
|
const attributeModels = attributes.map(attribute =>
|
|
74
|
-
new
|
|
77
|
+
new AttributeModel(attribute.name, attribute.type, attribute.values));
|
|
75
78
|
|
|
76
|
-
return new
|
|
79
|
+
return new PolicyModel(policyData.name, attributeModels);
|
|
77
80
|
};
|
|
78
81
|
|
|
79
|
-
const getCreateRequirementModel = function(
|
|
80
|
-
const policies =
|
|
82
|
+
const getCreateRequirementModel = function(requirement) {
|
|
83
|
+
const { policies, name, sharingLevel } = requirement;
|
|
84
|
+
|
|
85
|
+
const parsedPolicies = parseRequirementConfig(policies);
|
|
86
|
+
const policyModels = parsedPolicies.map(policy => getPolicyModel(policy));
|
|
87
|
+
|
|
88
|
+
return new CreateRequirementModel(name, policyModels, sharingLevel);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const getUpdateRequirementModel = function(requirementId, requirementPolicies, requirementName, accountId, projectId, tabId, dateModified) {
|
|
92
|
+
const policies = parseRequirementConfig(requirementPolicies);
|
|
81
93
|
const policyModels = policies.map(policy => getPolicyModel(policy));
|
|
82
94
|
|
|
83
|
-
return new
|
|
95
|
+
return new UpdateRequirementModel(requirementId, accountId, projectId, tabId, requirementName, policyModels, dateModified);
|
|
84
96
|
};
|
|
85
97
|
|
|
86
98
|
module.exports = {
|
|
87
|
-
getCreateRequirementModel
|
|
99
|
+
getCreateRequirementModel,
|
|
100
|
+
getUpdateRequirementModel
|
|
88
101
|
};
|