@getjones/test-infra 2.7.14 → 2.8.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 +1 -1
- package/src/factory/records/records.js +1 -1
- package/src/saas/internal-api/compliance/api/overrideGap/override.gap.api.js +19 -5
- package/src/saas/internal-api/compliance/api/overrideGap/override.gap.service.js +37 -43
- package/src/saas/internal-api/compliance/index.js +2 -4
- package/src/saas/internal-api/compliance/models/audit/audit.model.js +2 -2
- package/src/saas/internal-api/compliance/models/waive/waive.model.js +49 -0
- package/src/saas/internal-api/compliance/utils/auditUtil.js +17 -6
- package/src/saas/internal-api/users/api/tenantApp/tenant.app.api.js +32 -0
- package/src/saas/internal-api/users/api/tenantApp/tenant.app.service.js +78 -0
- package/src/saas/internal-api/users/index.js +7 -1
- package/src/saas/internal-api/users/models/tenent.user.model.js +11 -0
- package/src/saas/internal-api/compliance/consts/overrideGap.js +0 -10
- package/src/saas/internal-api/compliance/models/overrideGap/override.gap.model.js +0 -16
- package/src/saas/internal-api/compliance/models/overrideGap/retract.override.gap.model.js +0 -14
package/package.json
CHANGED
|
@@ -113,7 +113,7 @@ const prepareWaivedRecord = async (recordCompany, recordEmail, tabId, requiremen
|
|
|
113
113
|
const recordId = await prepareRecord(recordCompany, recordEmail, complianceStatuses.notCompliant, tabId, requirementId, context);
|
|
114
114
|
|
|
115
115
|
const { data: record } = await contractors.services.getContractorById(recordId, context);
|
|
116
|
-
await compliance.services.overrideGap.
|
|
116
|
+
await compliance.services.overrideGap.waiveAll(record, context);
|
|
117
117
|
|
|
118
118
|
return recordId;
|
|
119
119
|
};
|
|
@@ -2,18 +2,32 @@ const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
|
2
2
|
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
3
|
|
|
4
4
|
const Endpoints = {
|
|
5
|
+
waive: contractorId => `${backendUrl}/saas/contractors/${contractorId}/waiver`,
|
|
6
|
+
retract: contractorId => `${backendUrl}/saas/contractors/${contractorId}/waiver`,
|
|
5
7
|
overrideGap: `${backendUrl}/saas/record/override-gap`,
|
|
6
8
|
retractOverride: `${backendUrl}/saas/record/retract-override`
|
|
7
9
|
};
|
|
8
10
|
|
|
9
|
-
const
|
|
11
|
+
const waive = async (contractorId, waiveRequestModel, context) => {
|
|
12
|
+
const status = waiveRequestModel.status;
|
|
13
|
+
delete waiveRequestModel.status;
|
|
14
|
+
return requests.postRequestHandler(Endpoints.waive(contractorId), waiveRequestModel, context, {}, { status });
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const retract = async (contractorId, retractRequestModel, context) => {
|
|
18
|
+
const status = retractRequestModel.status;
|
|
19
|
+
delete retractRequestModel.status;
|
|
20
|
+
return requests.postRequestHandler(Endpoints.retract(contractorId), retractRequestModel, context, {}, { status });
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const overrideGap = ({ waiveRequestModel, isTestingBackwardCompatibility = false, context }) => {
|
|
10
24
|
const headers = {};
|
|
11
25
|
const params = { isTestingBackwardCompatibility };
|
|
12
|
-
return requests.postRequestHandler(Endpoints.overrideGap,
|
|
26
|
+
return requests.postRequestHandler(Endpoints.overrideGap, waiveRequestModel, context, headers, params);
|
|
13
27
|
};
|
|
14
28
|
|
|
15
|
-
const retractOverride = (
|
|
16
|
-
return requests.postRequestHandler(Endpoints.retractOverride,
|
|
29
|
+
const retractOverride = (retractRequestModel, context) => {
|
|
30
|
+
return requests.postRequestHandler(Endpoints.retractOverride, retractRequestModel, context);
|
|
17
31
|
};
|
|
18
32
|
|
|
19
|
-
module.exports = { overrideGap, retractOverride };
|
|
33
|
+
module.exports = { waive, retract, overrideGap, retractOverride };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
const env = require('../../../../../env');
|
|
2
2
|
|
|
3
3
|
const overrideGapApi = require('./override.gap.api');
|
|
4
|
-
const {
|
|
5
|
-
const { RetractOverrideGapModel } = require('../../models/overrideGap/retract.override.gap.model');
|
|
6
|
-
const { OVERRIDE_GAP_REASONS } = require('../../consts/overrideGap');
|
|
4
|
+
const { WaiveRequestModel, RetractRequestModel, WAIVER_REASONS } = require('../../models/waive/waive.model');
|
|
7
5
|
const { validateType } = require('../../../../../common/validations/typeValidations');
|
|
8
6
|
const auditUtil = require('../../utils/auditUtil');
|
|
9
7
|
const httpResponseStatusCodes = require('../../../../../common/httpResponseStatusCodes.json');
|
|
@@ -11,21 +9,31 @@ const httpResponseStatusCodes = require('../../../../../common/httpResponseStatu
|
|
|
11
9
|
const { credentials } = env.getEnv();
|
|
12
10
|
const userTypes = require('../../../../../common/consts/userTypes');
|
|
13
11
|
|
|
14
|
-
const
|
|
15
|
-
validateType(
|
|
16
|
-
return overrideGapApi.
|
|
12
|
+
const waive = (waiveRequestModel, context) => {
|
|
13
|
+
validateType(waiveRequestModel, WaiveRequestModel);
|
|
14
|
+
return overrideGapApi.waive(waiveRequestModel.contractorId, waiveRequestModel, context);
|
|
17
15
|
};
|
|
18
16
|
|
|
19
|
-
const
|
|
20
|
-
validateType(
|
|
21
|
-
return overrideGapApi.
|
|
17
|
+
const retract = (retractRequestModel, context) => {
|
|
18
|
+
validateType(retractRequestModel, RetractRequestModel);
|
|
19
|
+
return overrideGapApi.retract(retractRequestModel.contractorId, retractRequestModel, context);
|
|
22
20
|
};
|
|
23
21
|
|
|
24
|
-
const
|
|
22
|
+
const overrideGap = ({ waiveRequestModel, isTestingBackwardCompatibility = false, context }) => {
|
|
23
|
+
validateType(waiveRequestModel, WaiveRequestModel);
|
|
24
|
+
return overrideGapApi.overrideGap({ waiveRequestModel, isTestingBackwardCompatibility, context });
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
const retractOverride = (retractRequestModel, context) => {
|
|
28
|
+
validateType(retractRequestModel, RetractRequestModel);
|
|
29
|
+
return overrideGapApi.retractOverride(retractRequestModel, context);
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
const getWaiveModel = (
|
|
25
33
|
record,
|
|
26
34
|
policyName,
|
|
27
35
|
attributeName,
|
|
28
|
-
|
|
36
|
+
waiverReason,
|
|
29
37
|
remarks,
|
|
30
38
|
{
|
|
31
39
|
userId,
|
|
@@ -35,19 +43,19 @@ const getOverrideGapModel = (
|
|
|
35
43
|
userId = userId || env.getSystemUserIdentity(credentials.superUser).id;
|
|
36
44
|
userRole = userRole || userTypes.ICS;
|
|
37
45
|
|
|
38
|
-
const
|
|
46
|
+
const waiveModel = new WaiveRequestModel({
|
|
39
47
|
contractorId: record.id,
|
|
40
48
|
auditId,
|
|
41
|
-
|
|
49
|
+
waiverReason,
|
|
42
50
|
remarks,
|
|
43
51
|
userId,
|
|
44
52
|
userRole
|
|
45
53
|
});
|
|
46
54
|
|
|
47
|
-
return
|
|
55
|
+
return waiveModel;
|
|
48
56
|
};
|
|
49
57
|
|
|
50
|
-
const
|
|
58
|
+
const getWaiveModelByGap = (
|
|
51
59
|
record,
|
|
52
60
|
policyName,
|
|
53
61
|
gap,
|
|
@@ -59,7 +67,7 @@ const getOverrideGapModelByGap = (
|
|
|
59
67
|
} = {}) => {
|
|
60
68
|
const attributeName = auditUtil.getAttributeNameByGap(record, policyName, gap);
|
|
61
69
|
|
|
62
|
-
return
|
|
70
|
+
return getWaiveModel(record, policyName, attributeName, reason, note, { userId, userRole });
|
|
63
71
|
};
|
|
64
72
|
|
|
65
73
|
const getRetractModel = (record, policyName, attributeName) => {
|
|
@@ -67,7 +75,7 @@ const getRetractModel = (record, policyName, attributeName) => {
|
|
|
67
75
|
const userId = env.getSystemUserIdentity(credentials.superUser).id;
|
|
68
76
|
const userRole = userTypes.ICS;
|
|
69
77
|
|
|
70
|
-
const retractModel = new
|
|
78
|
+
const retractModel = new RetractRequestModel({
|
|
71
79
|
contractorId: record.id,
|
|
72
80
|
auditId,
|
|
73
81
|
userId,
|
|
@@ -94,40 +102,26 @@ const getPolicyAuditIdFromRecord = (record, policyName, attributeName) => {
|
|
|
94
102
|
return attribute.auditId;
|
|
95
103
|
};
|
|
96
104
|
|
|
97
|
-
|
|
98
|
-
const
|
|
99
|
-
const allOverriddenPolicies = auditUtil.getAllOverriddenGapPolicies(record, context);
|
|
105
|
+
const waiveAll = async (record, context, { reason = WAIVER_REASONS.BUSINESS_DECISION, note = 'WAIVED AUTOMATICALLY' } = {}) => {
|
|
106
|
+
const allWaivablePolicies = auditUtil.getAllWaivablePolicies(record, context);
|
|
100
107
|
|
|
101
|
-
for (const
|
|
102
|
-
const
|
|
103
|
-
const
|
|
108
|
+
for (const waivable of allWaivablePolicies) {
|
|
109
|
+
const waiveModel = getWaiveModel(record, waivable.policyName, waivable.attributeName, reason, note);
|
|
110
|
+
const waiveResponse = await waive(waiveModel, context);
|
|
104
111
|
|
|
105
|
-
if (
|
|
106
|
-
throw Error(`Failed to
|
|
112
|
+
if (waiveResponse.status !== httpResponseStatusCodes.OK) {
|
|
113
|
+
throw Error(`Failed to waive ${waivable.policyName} - ${waivable.attributeName} for ${record.company}`);
|
|
107
114
|
}
|
|
108
115
|
}
|
|
109
116
|
};
|
|
110
117
|
|
|
111
|
-
const waiveAllGaps = async (record, context, { reason = OVERRIDE_GAP_REASONS.BUSINESS_DECISION, note = 'WAIVED AUTOMATICALLY' } = {}) => {
|
|
112
|
-
const waivedReasons = new Set([OVERRIDE_GAP_REASONS.BUSINESS_DECISION, OVERRIDE_GAP_REASONS.EXECUTIVE_APPROVAL, OVERRIDE_GAP_REASONS.NO_EXPOSURE]);
|
|
113
|
-
|
|
114
|
-
if (!waivedReasons.has(reason)) {
|
|
115
|
-
throw Error(`Invalid waive reason ${reason} provided when trying to waive all gaps to waive`);
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
await overrideAllGaps(record, context, { reason, note });
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
const acceptAllGaps = async (record, context, { note = 'ACCEPTED AUTOMATICALLY' } = {}) => {
|
|
122
|
-
overrideAllGaps(record, context, { reason: OVERRIDE_GAP_REASONS.ACCEPT_NO_EXPOSURE, note });
|
|
123
|
-
};
|
|
124
|
-
|
|
125
118
|
module.exports = {
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
119
|
+
waive,
|
|
120
|
+
waiveAll,
|
|
121
|
+
retract,
|
|
122
|
+
getWaiveModel,
|
|
129
123
|
getRetractModel,
|
|
130
|
-
|
|
124
|
+
getWaiveModelByGap,
|
|
131
125
|
overrideGap,
|
|
132
126
|
retractOverride
|
|
133
127
|
};
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
const auditModels = require('./models/audit/audit.model');
|
|
2
2
|
const auditServices = require('./api/audit/audit.service');
|
|
3
3
|
|
|
4
|
-
const waiveModels = require('./models/
|
|
4
|
+
const waiveModels = require('./models/waive/waive.model');
|
|
5
5
|
const overrideGapServices = require('./api/overrideGap/override.gap.service');
|
|
6
6
|
|
|
7
7
|
const convertServices = require('./api/convert/convert.service');
|
|
8
8
|
const coverageServices = require('./api/coverage/coverage.service');
|
|
9
9
|
|
|
10
10
|
const auditConsts = require('./consts/audit');
|
|
11
|
-
const overrideGapConsts = require('./consts/overrideGap');
|
|
12
11
|
const auditUtils = require('./utils/auditUtil');
|
|
13
12
|
|
|
14
13
|
const models = {
|
|
@@ -17,8 +16,7 @@ const models = {
|
|
|
17
16
|
};
|
|
18
17
|
|
|
19
18
|
const consts = {
|
|
20
|
-
audit: auditConsts
|
|
21
|
-
overrideGap: overrideGapConsts
|
|
19
|
+
audit: auditConsts
|
|
22
20
|
};
|
|
23
21
|
|
|
24
22
|
const utils = {
|
|
@@ -59,7 +59,7 @@ class AuditDatesModel {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
class AuditListParametersModel {
|
|
62
|
-
constructor(page, accountIds, { fromDate, toDate } = {}) {
|
|
62
|
+
constructor(page, accountIds, { fromDate, toDate, recordId } = {}) {
|
|
63
63
|
validateInteger(page, { min: 1 });
|
|
64
64
|
validateArray(accountIds);
|
|
65
65
|
|
|
@@ -72,7 +72,7 @@ class AuditListParametersModel {
|
|
|
72
72
|
}
|
|
73
73
|
|
|
74
74
|
this.page = page;
|
|
75
|
-
this.filters = { accountIds, fromDate, toDate };
|
|
75
|
+
this.filters = { accountIds, fromDate, toDate, recordId };
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
const WAIVE_ACTIONS = {
|
|
2
|
+
WAIVE: 'ignored',
|
|
3
|
+
RETRACT: 'notIgnored'
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
const WAIVER_REASONS = {
|
|
7
|
+
BUSINESS_DECISION: 'Business Decision',
|
|
8
|
+
EXECUTIVE_APPROVAL: 'Executive Approval',
|
|
9
|
+
ACCEPT_NO_EXPOSURE: 'Accept / No Exposure',
|
|
10
|
+
NO_EXPOSURE: 'No Exposure' // DEPRECATED - BACKWARD COMPATIBILITY
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function WaiveRequestModel({
|
|
14
|
+
contractorId,
|
|
15
|
+
auditId,
|
|
16
|
+
waiverReason,
|
|
17
|
+
remarks,
|
|
18
|
+
userId,
|
|
19
|
+
userRole
|
|
20
|
+
}) {
|
|
21
|
+
this.auditorContractorId = auditId;
|
|
22
|
+
this.contractorId = contractorId;
|
|
23
|
+
this.waiverReason = waiverReason;
|
|
24
|
+
this.remarks = remarks || '';
|
|
25
|
+
|
|
26
|
+
this.userId = userId,
|
|
27
|
+
this.userRole = userRole,
|
|
28
|
+
this.status = WAIVE_ACTIONS.WAIVE;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
function RetractRequestModel({
|
|
32
|
+
contractorId,
|
|
33
|
+
auditId,
|
|
34
|
+
userId,
|
|
35
|
+
userRole
|
|
36
|
+
}) {
|
|
37
|
+
this.auditorContractorId = auditId;
|
|
38
|
+
this.contractorId = contractorId;
|
|
39
|
+
this.userId = userId;
|
|
40
|
+
this.userRole = userRole;
|
|
41
|
+
this.status = WAIVE_ACTIONS.RETRACT;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
module.exports = {
|
|
45
|
+
WaiveRequestModel,
|
|
46
|
+
RetractRequestModel,
|
|
47
|
+
WAIVE_ACTIONS,
|
|
48
|
+
WAIVER_REASONS
|
|
49
|
+
};
|
|
@@ -2,7 +2,7 @@ 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 waiveModels = require('../models/waive/waive.model');
|
|
6
6
|
|
|
7
7
|
const emptyValue = '';
|
|
8
8
|
|
|
@@ -22,6 +22,10 @@ const getAttributeKey = attribute => {
|
|
|
22
22
|
return specialAttributes[attribute] || attribute;
|
|
23
23
|
};
|
|
24
24
|
|
|
25
|
+
const getWaiveReason = reason => {
|
|
26
|
+
return waiveReasons[reason] || reason;
|
|
27
|
+
};
|
|
28
|
+
|
|
25
29
|
const getAttributeNameByGap = function(record, policyName, gap) {
|
|
26
30
|
const policy = record.reviewbyAuditor.find(contractorCoverage =>
|
|
27
31
|
contractorCoverage.insuranceName === policyName);
|
|
@@ -39,8 +43,8 @@ const getAttributeNameByGap = function(record, policyName, gap) {
|
|
|
39
43
|
return attribute.limitname;
|
|
40
44
|
};
|
|
41
45
|
|
|
42
|
-
const
|
|
43
|
-
const
|
|
46
|
+
const getAllWaivablePolicies = function(record) {
|
|
47
|
+
const waivable = [];
|
|
44
48
|
|
|
45
49
|
const policies = record.reviewbyAuditor;
|
|
46
50
|
for (const policy of policies) {
|
|
@@ -51,7 +55,7 @@ const getAllOverriddenGapPolicies = function(record) {
|
|
|
51
55
|
|
|
52
56
|
for (const error of errorList) {
|
|
53
57
|
if (error.warningStatus === 'POLICYERROR' && error.errorStatus === 'notIgnored') {
|
|
54
|
-
|
|
58
|
+
waivable.push({
|
|
55
59
|
policyName: policyName,
|
|
56
60
|
attributeName: error.limitname
|
|
57
61
|
});
|
|
@@ -59,7 +63,7 @@ const getAllOverriddenGapPolicies = function(record) {
|
|
|
59
63
|
}
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
return
|
|
66
|
+
return waivable;
|
|
63
67
|
};
|
|
64
68
|
|
|
65
69
|
const getPolicyId = (policyName, requirement) => {
|
|
@@ -172,7 +176,8 @@ module.exports = {
|
|
|
172
176
|
createAuditEntity,
|
|
173
177
|
getAttributeKey,
|
|
174
178
|
getAttributeNameByGap,
|
|
175
|
-
|
|
179
|
+
getWaiveReason,
|
|
180
|
+
getAllWaivablePolicies
|
|
176
181
|
};
|
|
177
182
|
|
|
178
183
|
const certificateEndorsmentsList = [
|
|
@@ -209,3 +214,9 @@ const specialAttributes = {
|
|
|
209
214
|
'Umbrella': 'UMoccur'
|
|
210
215
|
}
|
|
211
216
|
};
|
|
217
|
+
|
|
218
|
+
const waiveReasons = {
|
|
219
|
+
'No Exposure': waiveModels.WAIVER_REASONS.NO_EXPOSURE,
|
|
220
|
+
'Business Decision': waiveModels.WAIVER_REASONS.BUSINESS_DECISION,
|
|
221
|
+
'Executive Approval': waiveModels.WAIVER_REASONS.EXECUTIVE_APPROVAL
|
|
222
|
+
};
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
const requests = require('../../../../../common/requests/cookieAuth/requests');
|
|
2
|
+
const { backendUrl } = require('../../../../../env').getEnv();
|
|
3
|
+
|
|
4
|
+
const Endpoints = {
|
|
5
|
+
invite: projectId => `${backendUrl}/saas/project/${projectId}/tenants`,
|
|
6
|
+
getTenantsByProjectId: projectId => `${backendUrl}/saas/project/${projectId}/tenants`,
|
|
7
|
+
signupUser: `${backendUrl}/_saas/guests/signup`,
|
|
8
|
+
removeTenantUser: (projectId, userId) => `${backendUrl}/saas/project/${projectId}/tenant/${userId}`
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
const invite = (projectId, invitedTenantUser, context) => {
|
|
12
|
+
return requests.putRequestHandler(Endpoints.invite(projectId), invitedTenantUser, context, {}, { disableSendMail });
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
const getTenantUsersByProjectId = (projectId, context) => {
|
|
16
|
+
return requests.getRequestHandler(Endpoints.getTenantsByProjectId(projectId), {}, context, {});
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const signupUser = (signupUserModel, context) => {
|
|
20
|
+
return requests.postRequestHandler(Endpoints.signupUser, signupUserModel, context, {}, {});
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
const removeTenantUser = (projectId, tenantId, context) => {
|
|
24
|
+
return requests.deleteRequestHandler(Endpoints.removeTenantUser(projectId, tenantId), context);
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
module.exports = {
|
|
28
|
+
invite,
|
|
29
|
+
getTenantUsersByProjectId,
|
|
30
|
+
signupUser,
|
|
31
|
+
removeTenantUser
|
|
32
|
+
};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
const { getEnv } = require('../../../../../env');
|
|
2
|
+
const httpResponseStatusCodes = require('../../../../../common/httpResponseStatusCodes.json');
|
|
3
|
+
|
|
4
|
+
const { credentials } = getEnv();
|
|
5
|
+
|
|
6
|
+
const { InviteTenantUserModel } = require('../../models/tenent.user.model');
|
|
7
|
+
const { validateType } = require('../../../../../common/validations/typeValidations');
|
|
8
|
+
const tenantAPI = require('./tenant.app.api');
|
|
9
|
+
const util = require('../../utils/util');
|
|
10
|
+
|
|
11
|
+
const inviteTenantUser = (projectId, invitedTenantUser, context) => {
|
|
12
|
+
validateType(invitedTenantUser, InviteTenantUserModel);
|
|
13
|
+
return tenantAPI.invite(projectId, invitedTenantUser, context);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
const signupUser = (signupUserModel, context) => {
|
|
17
|
+
return tenantAPI.signupUser(signupUserModel, context);
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
const removeTenantUser = (projectId, tenantId, context) => {
|
|
21
|
+
return tenantAPI.removeTenantUser(projectId, tenantId, context);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
const getTenantUsersByProjectId = async (projectId, context) => {
|
|
25
|
+
const tenantResponse = await tenantAPI.getTenantsUserByProjectId(projectId, context);
|
|
26
|
+
|
|
27
|
+
if (tenantResponse.status !== httpResponseStatusCodes.OK) {
|
|
28
|
+
throw new Error(`Failed to retrieve tenants users from project\n${tenantResponse.status}`);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return tenantResponse.data;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
const getTenantUserByEmail = async (projectId, email, context) => {
|
|
35
|
+
const allTenants = await getTenantUsersByProjectId(projectId, context);
|
|
36
|
+
|
|
37
|
+
const tenant = allTenants.find(tenant => tenant.email === email);
|
|
38
|
+
return tenant;
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
const getOrCreateTenantUser = async (projectId, email, company, requestId, context, { fullName = 'Tenant User', password = credentials.strongPassword } = {}) => {
|
|
42
|
+
let tenantUser = await getTenantUserByEmail(projectId, email, context);
|
|
43
|
+
|
|
44
|
+
if (tenantUser && tenantUser.subuserId && tenantUser.isVerified) {
|
|
45
|
+
return tenantUser;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const inviteUserModel = new InviteTenantUserModel(email, company, requestId);
|
|
49
|
+
const inviteResponse = await inviteTenantUser(projectId, inviteUserModel, context);
|
|
50
|
+
|
|
51
|
+
if (inviteResponse.status !== httpResponseStatusCodes.OK) {
|
|
52
|
+
throw new Error(`Failed to invite tenant user with email: ${email}\n${inviteResponse}`);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
tenantUser = await getTenantUserByEmail(projectId, email, context);
|
|
56
|
+
|
|
57
|
+
//Already signup tenant user
|
|
58
|
+
if (tenantUser.isVerified) {
|
|
59
|
+
return tenantUser;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const signupUserModel = await util.getSignupUserModel(email, 'Admin', fullName, password, context);
|
|
63
|
+
const signupResponse = await signupUser(signupUserModel, context);
|
|
64
|
+
|
|
65
|
+
if (signupResponse.status !== httpResponseStatusCodes.OK) {
|
|
66
|
+
throw new Error(`Failed to signup tenant user with email: ${email}\n${signupResponse}`);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
tenantUser = await getTenantUserByEmail(projectId, email, context);
|
|
70
|
+
return tenantUser;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
module.exports = {
|
|
74
|
+
inviteTenantUser,
|
|
75
|
+
getTenantUsersByProjectId,
|
|
76
|
+
getOrCreateTenantUser,
|
|
77
|
+
removeTenantUser
|
|
78
|
+
};
|
|
@@ -2,4 +2,10 @@ const models = require('./models/users.model');
|
|
|
2
2
|
const services = require('./api/users.service');
|
|
3
3
|
const util = require('./utils/util');
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
const tenantUserService = require('./api/tenantApp/tenant.app.service');
|
|
6
|
+
|
|
7
|
+
const tenants = {
|
|
8
|
+
services: tenantUserService
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
module.exports = { services, models, util, tenants };
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
const OVERRIDE_GAP_REASONS = {
|
|
2
|
-
BUSINESS_DECISION: 'Business Decision',
|
|
3
|
-
EXECUTIVE_APPROVAL: 'Executive Approval',
|
|
4
|
-
ACCEPT_NO_EXPOSURE: 'Accept / No Exposure',
|
|
5
|
-
NO_EXPOSURE: 'No Exposure' // DEPRECATED - BACKWARD COMPATIBILITY
|
|
6
|
-
};
|
|
7
|
-
|
|
8
|
-
module.exports = {
|
|
9
|
-
OVERRIDE_GAP_REASONS
|
|
10
|
-
};
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
class OverrideGapModel {
|
|
2
|
-
constructor({
|
|
3
|
-
contractorId, auditId, reason, remarks, userId, userRole
|
|
4
|
-
}) {
|
|
5
|
-
this.auditorContractorId = auditId;
|
|
6
|
-
this.contractorId = contractorId;
|
|
7
|
-
this.reason = reason;
|
|
8
|
-
this.remarks = remarks || '';
|
|
9
|
-
this.userId = userId;
|
|
10
|
-
this.userRole = userRole;
|
|
11
|
-
}
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
module.exports = {
|
|
15
|
-
OverrideGapModel
|
|
16
|
-
};
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
class RetractOverrideGapModel {
|
|
2
|
-
constructor({
|
|
3
|
-
contractorId, auditId, userId, userRole
|
|
4
|
-
}) {
|
|
5
|
-
this.auditorContractorId = auditId;
|
|
6
|
-
this.contractorId = contractorId;
|
|
7
|
-
this.userId = userId;
|
|
8
|
-
this.userRole = userRole;
|
|
9
|
-
}
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
module.exports = {
|
|
13
|
-
RetractOverrideGapModel
|
|
14
|
-
};
|