@getjones/test-infra 2.1.2 → 2.1.4

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.
Files changed (135) hide show
  1. package/package.json +29 -29
  2. package/src/common/commonFlows/index.js +3 -3
  3. package/src/common/commonFlows/records/records.js +71 -71
  4. package/src/common/httpResponseStatusCodes.json +11 -11
  5. package/src/common/requests/apiKeyAuth/requests.js +38 -38
  6. package/src/common/requests/cookieAuth/requests.js +40 -40
  7. package/src/common/requests/requestHandlers.js +60 -60
  8. package/src/common/utils/dataTypeUtils.js +41 -0
  9. package/src/common/utils/numberUtils.js +22 -22
  10. package/src/common/utils/timeUtils.js +167 -162
  11. package/src/common/validations/errorValidation.js +16 -16
  12. package/src/common/validations/typeValidations.js +36 -36
  13. package/src/env.js +45 -45
  14. package/src/index.js +71 -69
  15. package/src/saas/internal-api/accounts/api/core/accounts.core.api.js +28 -28
  16. package/src/saas/internal-api/accounts/api/core/accounts.core.service.js +77 -77
  17. package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.api.js +48 -48
  18. package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.service.js +74 -74
  19. package/src/saas/internal-api/accounts/api/settings/settings.api.js +21 -21
  20. package/src/saas/internal-api/accounts/api/settings/settings.service.js +24 -24
  21. package/src/saas/internal-api/accounts/index.js +20 -20
  22. package/src/saas/internal-api/accounts/models/core/create.account.model.js +15 -15
  23. package/src/saas/internal-api/accounts/models/settings/update.settings.model.js +23 -21
  24. package/src/saas/internal-api/accounts/utils/utils.js +32 -32
  25. package/src/saas/internal-api/auth/api/auth.api.js +18 -12
  26. package/src/saas/internal-api/auth/api/auth.service.js +75 -47
  27. package/src/saas/internal-api/auth/index.js +3 -3
  28. package/src/saas/internal-api/coi/api/coi.api.js +34 -34
  29. package/src/saas/internal-api/coi/api/coi.service.js +22 -22
  30. package/src/saas/internal-api/coi/consts/uploaderTypes.js +7 -7
  31. package/src/saas/internal-api/coi/index.js +13 -13
  32. package/src/saas/internal-api/coi/models/submit.coi.model.js +9 -9
  33. package/src/saas/internal-api/coi/utils/utils.js +48 -48
  34. package/src/saas/internal-api/compliance/api/audit/audit.api.js +41 -40
  35. package/src/saas/internal-api/compliance/api/audit/audit.service.js +151 -33
  36. package/src/saas/internal-api/compliance/api/convert/convert.api.js +17 -17
  37. package/src/saas/internal-api/compliance/api/convert/convert.service.js +11 -11
  38. package/src/saas/internal-api/compliance/api/coverage/coverage.api.js +33 -33
  39. package/src/saas/internal-api/compliance/api/coverage/coverage.service.js +24 -24
  40. package/src/saas/internal-api/compliance/api/waive/waive.api.js +21 -21
  41. package/src/saas/internal-api/compliance/api/waive/waive.service.js +15 -15
  42. package/src/saas/internal-api/compliance/consts/audit.js +81 -81
  43. package/src/saas/internal-api/compliance/index.js +28 -28
  44. package/src/saas/internal-api/compliance/models/audit/audit.model.js +84 -84
  45. package/src/saas/internal-api/compliance/models/waive/waive.model.js +45 -45
  46. package/src/saas/internal-api/compliance/utils/util.js +173 -218
  47. package/src/saas/internal-api/contractors/api/contractors.api.js +141 -141
  48. package/src/saas/internal-api/contractors/api/contractors.service.js +123 -123
  49. package/src/saas/internal-api/contractors/index.js +8 -8
  50. package/src/saas/internal-api/contractors/models/create.contractor.model.js +22 -22
  51. package/src/saas/internal-api/contractors/models/edit.contractor.model.js +60 -60
  52. package/src/saas/internal-api/contractors/models/verification.contractor.model.js +27 -27
  53. package/src/saas/internal-api/dashboardInnerPage/api/recordList.api.js +12 -0
  54. package/src/saas/internal-api/dashboardInnerPage/api/recordList.service.js +7 -0
  55. package/src/saas/internal-api/dashboardInnerPage/index.js +5 -0
  56. package/src/saas/internal-api/dashboardInnerPage/models/dashboard.filter.criteria.model.js +38 -0
  57. package/src/saas/internal-api/dbEmails/api/db.emails.api.js +25 -25
  58. package/src/saas/internal-api/dbEmails/api/db.emails.service.js +127 -127
  59. package/src/saas/internal-api/dbEmails/consts/consts.js +3 -3
  60. package/src/saas/internal-api/dbEmails/index.js +4 -4
  61. package/src/saas/internal-api/dbEmails/models/db.emails.model.js +21 -21
  62. package/src/saas/internal-api/dbEmails/utils/util.js +59 -59
  63. package/src/saas/internal-api/globalRecord/api/global.record.api.js +76 -76
  64. package/src/saas/internal-api/globalRecord/api/global.record.service.js +83 -83
  65. package/src/saas/internal-api/globalRecord/consts.js +20 -20
  66. package/src/saas/internal-api/globalRecord/index.js +6 -6
  67. package/src/saas/internal-api/globalRecord/models/global.record.model.js +43 -43
  68. package/src/saas/internal-api/globalRecord/utils/util.js +148 -148
  69. package/src/saas/internal-api/homepageCharts/api/charts.api.js +12 -12
  70. package/src/saas/internal-api/homepageCharts/api/charts.service.js +7 -7
  71. package/src/saas/internal-api/homepageCharts/index.js +3 -3
  72. package/src/saas/internal-api/projects/api/core/projects.api.js +39 -39
  73. package/src/saas/internal-api/projects/api/core/projects.service.js +65 -65
  74. package/src/saas/internal-api/projects/api/settings/project.settings.api.js +18 -18
  75. package/src/saas/internal-api/projects/api/settings/project.settings.service.js +17 -17
  76. package/src/saas/internal-api/projects/consts/defaultProject.js +3 -3
  77. package/src/saas/internal-api/projects/index.js +24 -24
  78. package/src/saas/internal-api/projects/models/core/create.project.model.js +41 -41
  79. package/src/saas/internal-api/projects/models/core/update.project.model.js +47 -47
  80. package/src/saas/internal-api/projects/models/settings/update.project.settings.model.js +39 -39
  81. package/src/saas/internal-api/projects/utils/utils.js +82 -82
  82. package/src/saas/internal-api/recordNotes/api/record.notes.api.js +38 -38
  83. package/src/saas/internal-api/recordNotes/api/record.notes.service.js +29 -29
  84. package/src/saas/internal-api/recordNotes/index.js +3 -3
  85. package/src/saas/internal-api/reports/api/reports.api.js +39 -39
  86. package/src/saas/internal-api/reports/api/reports.service.js +34 -34
  87. package/src/saas/internal-api/reports/consts/consts.js +63 -63
  88. package/src/saas/internal-api/reports/index.js +15 -15
  89. package/src/saas/internal-api/reports/models/report.model.js +27 -27
  90. package/src/saas/internal-api/requests/api/requests.api.js +54 -54
  91. package/src/saas/internal-api/requests/api/requests.service.js +51 -51
  92. package/src/saas/internal-api/requests/index.js +14 -14
  93. package/src/saas/internal-api/requests/models/create.request.model.js +22 -22
  94. package/src/saas/internal-api/requests/models/edit.request.model.js +31 -31
  95. package/src/saas/internal-api/requests/models/tenant.request.model.js +9 -9
  96. package/src/saas/internal-api/requests/utils.js +8 -8
  97. package/src/saas/internal-api/requirements/api/requirements.api.js +27 -27
  98. package/src/saas/internal-api/requirements/api/requirements.service.js +23 -23
  99. package/src/saas/internal-api/requirements/consts/attributeTypes.json +6 -0
  100. package/src/saas/internal-api/requirements/index.js +6 -6
  101. package/src/saas/internal-api/requirements/models/create.requirement.model.js +45 -45
  102. package/src/saas/internal-api/requirements/utils/utils.js +88 -0
  103. package/src/saas/internal-api/serviceArea/api/coordinates.api.js +12 -12
  104. package/src/saas/internal-api/serviceArea/api/coordinates.service.js +7 -7
  105. package/src/saas/internal-api/serviceArea/index.js +4 -4
  106. package/src/saas/internal-api/serviceArea/utils/utils.js +8 -8
  107. package/src/saas/internal-api/tabs/api/tabs.api.js +32 -32
  108. package/src/saas/internal-api/tabs/api/tabs.service.js +54 -54
  109. package/src/saas/internal-api/tabs/index.js +3 -3
  110. package/src/saas/internal-api/tabs/models/tabs.model.js +18 -18
  111. package/src/saas/internal-api/thread-scheduler/runner.js +13 -13
  112. package/src/saas/internal-api/users/api/users.api.js +77 -77
  113. package/src/saas/internal-api/users/api/users.service.js +101 -101
  114. package/src/saas/internal-api/users/index.js +4 -4
  115. package/src/saas/internal-api/users/models/users.model.js +31 -31
  116. package/src/saas/internal-api/users/utils/util.js +14 -14
  117. package/src/saas/internal-api/vendorProfile/api/vendor.profile.api.js +20 -20
  118. package/src/saas/internal-api/vendorProfile/api/vendor.profile.service.js +14 -14
  119. package/src/saas/internal-api/vendorProfile/index.js +3 -3
  120. package/src/saas/openapi/accounts/accounts.api.js +17 -17
  121. package/src/saas/openapi/accounts/accounts.service.js +11 -11
  122. package/src/saas/openapi/projects/projects.api.js +59 -59
  123. package/src/saas/openapi/projects/projects.service.js +44 -44
  124. package/src/saas/openapi/requests/index.js +6 -6
  125. package/src/saas/openapi/requests/models/invite.request.model.js +37 -37
  126. package/src/saas/openapi/requests/requests.api.js +20 -20
  127. package/src/saas/openapi/requests/requests.service.js +18 -18
  128. package/src/saas/openapi/requirements/index.js +6 -6
  129. package/src/saas/openapi/requirements/models/copy.requirement.model.js +10 -10
  130. package/src/saas/openapi/requirements/requirements.api.js +12 -12
  131. package/src/saas/openapi/requirements/requirements.service.js +20 -20
  132. package/src/saas/openapi/tabs/tabs.api.js +13 -13
  133. package/src/saas/openapi/tabs/tabs.service.js +7 -7
  134. package/tests/env.test.js +40 -40
  135. package/tests/validation.test.js +83 -83
@@ -1,84 +1,84 @@
1
- const { validateType, validateInteger, validateArray, validateDateString } = require('../../../../../common/validations/typeValidations');
2
- const { AUDITOR_ROLE, COI_AUDIT_STATUSES } = require('../../consts/audit');
3
-
4
- class AuditRequestModel {
5
- constructor(
6
- accountId = null,
7
- projectId = null,
8
- requirementId = null,
9
- contractorId = null,
10
- certificateId = null,
11
- auditorId = null,
12
- auditEntities = null,
13
- isReaudit = null,
14
- isProjectOnboarding = false,
15
- shouldSendNotificationToPM = true,
16
- auditDates = {},
17
- auditStatus = null,
18
- auditorRole = AUDITOR_ROLE
19
- ) {
20
- const auditData = {
21
- userId: accountId,
22
- projectId: projectId,
23
- requirementId: requirementId,
24
- contractorId: contractorId,
25
- certificateId: certificateId,
26
- auditorId: auditorId,
27
- policyDetails: auditEntities,
28
- auditorStatus: COI_AUDIT_STATUSES.NOT_AUDITED,
29
- isReaudit: isReaudit,
30
- projectOnboarding: isProjectOnboarding,
31
- role: auditorRole,
32
- sendNotificationToPM: shouldSendNotificationToPM,
33
- auditStatus
34
- };
35
-
36
- validateType(auditDates, AuditDatesModel);
37
- this.auditData = auditData;
38
- this.auditDates = auditDates;
39
- }
40
- }
41
-
42
- class AuditEntityModel {
43
- constructor(policyId, attributeName, status, value) {
44
- this.contractorInsuranceId = policyId;
45
- this.limitname = attributeName;
46
- this.status = status;
47
- this.value = value;
48
- }
49
- }
50
-
51
- class AuditDatesModel {
52
- constructor(contractorId, contractorDateModified, dateStartedAudit, contractorOverrideDateModified, contractCreateDate) {
53
- this.contractorId = contractorId;
54
- this.contractorDateModified = contractorDateModified;
55
- this.dateStartedAudit = dateStartedAudit;
56
- this.contractorOverrideDateModified = contractorOverrideDateModified;
57
- this.contractCreateDate = contractCreateDate;
58
- }
59
- }
60
-
61
- class AuditListParametersModel {
62
- constructor(page, accountIds, { fromDate, toDate } = {}) {
63
- validateInteger(page, { min: 1 });
64
- validateArray(accountIds);
65
-
66
- if (fromDate) {
67
- validateDateString(fromDate);
68
- }
69
-
70
- if (toDate) {
71
- validateDateString(toDate);
72
- }
73
-
74
- this.page = page;
75
- this.filters = { accountIds, fromDate, toDate };
76
- }
77
- }
78
-
79
- module.exports = {
80
- AuditRequestModel,
81
- AuditEntityModel,
82
- AuditDatesModel,
83
- AuditListParametersModel
84
- };
1
+ const { validateType, validateInteger, validateArray, validateDateString } = require('../../../../../common/validations/typeValidations');
2
+ const { AUDITOR_ROLE, COI_AUDIT_STATUSES } = require('../../consts/audit');
3
+
4
+ class AuditRequestModel {
5
+ constructor(
6
+ accountId = null,
7
+ projectId = null,
8
+ requirementId = null,
9
+ contractorId = null,
10
+ certificateId = null,
11
+ auditorId = null,
12
+ auditEntities = null,
13
+ isReaudit = null,
14
+ isProjectOnboarding = false,
15
+ shouldSendNotificationToPM = true,
16
+ auditDates = {},
17
+ auditStatus = null,
18
+ auditorRole = AUDITOR_ROLE
19
+ ) {
20
+ const auditData = {
21
+ userId: accountId,
22
+ projectId: projectId,
23
+ requirementId: requirementId,
24
+ contractorId: contractorId,
25
+ certificateId: certificateId,
26
+ auditorId: auditorId,
27
+ policyDetails: auditEntities,
28
+ auditorStatus: COI_AUDIT_STATUSES.NOT_AUDITED,
29
+ isReaudit: isReaudit,
30
+ projectOnboarding: isProjectOnboarding,
31
+ role: auditorRole,
32
+ sendNotificationToPM: shouldSendNotificationToPM,
33
+ auditStatus
34
+ };
35
+
36
+ validateType(auditDates, AuditDatesModel);
37
+ this.auditData = auditData;
38
+ this.auditDates = auditDates;
39
+ }
40
+ }
41
+
42
+ class AuditEntityModel {
43
+ constructor(policyId, attributeName, status, value) {
44
+ this.contractorInsuranceId = policyId;
45
+ this.limitname = attributeName;
46
+ this.status = status;
47
+ this.value = value;
48
+ }
49
+ }
50
+
51
+ class AuditDatesModel {
52
+ constructor(contractorId, contractorDateModified, dateStartedAudit, contractorOverrideDateModified, contractCreateDate) {
53
+ this.contractorId = contractorId;
54
+ this.contractorDateModified = contractorDateModified;
55
+ this.dateStartedAudit = dateStartedAudit;
56
+ this.contractorOverrideDateModified = contractorOverrideDateModified;
57
+ this.contractCreateDate = contractCreateDate;
58
+ }
59
+ }
60
+
61
+ class AuditListParametersModel {
62
+ constructor(page, accountIds, { fromDate, toDate } = {}) {
63
+ validateInteger(page, { min: 1 });
64
+ validateArray(accountIds);
65
+
66
+ if (fromDate) {
67
+ validateDateString(fromDate);
68
+ }
69
+
70
+ if (toDate) {
71
+ validateDateString(toDate);
72
+ }
73
+
74
+ this.page = page;
75
+ this.filters = { accountIds, fromDate, toDate };
76
+ }
77
+ }
78
+
79
+ module.exports = {
80
+ AuditRequestModel,
81
+ AuditEntityModel,
82
+ AuditDatesModel,
83
+ AuditListParametersModel
84
+ };
@@ -1,45 +1,45 @@
1
- const DEFAULT_USER_ROLE = 'ICS';
2
-
3
- const WAIVE_ACTIONS = {
4
- WAIVE: 'ignored',
5
- RETRACT: 'notIgnored'
6
- };
7
-
8
- const WAIVER_REASONS = {
9
- BUSINESS_DECISION: 'Business_Decision',
10
- NO_EXPOSURE: 'No_Exposure',
11
- EXECUTIVE_APPROVAL: 'Executive_Approval'
12
- };
13
-
14
- function WaiveRequestModel({
15
- userId,
16
- contractorId,
17
- auditId,
18
- waiverReason,
19
- remarks = '',
20
- userRole = DEFAULT_USER_ROLE
21
- }) {
22
- this.auditorContractorId = auditId;
23
- this.contractorId = contractorId;
24
- this.userId = userId;
25
- this.waiverReason = waiverReason;
26
- this.remarks = remarks;
27
-
28
- this.userRole = userRole;
29
- this.status = WAIVE_ACTIONS.WAIVE;
30
- }
31
-
32
- function RetractRequestModel({ userId, contractorId, auditId, userRole = DEFAULT_USER_ROLE }) {
33
- this.auditorContractorId = auditId;
34
- this.contractorId = contractorId;
35
- this.userId = userId;
36
- this.userRole = userRole;
37
- this.status = WAIVE_ACTIONS.RETRACT;
38
- }
39
-
40
- module.exports = {
41
- WaiveRequestModel,
42
- RetractRequestModel,
43
- WAIVE_ACTIONS,
44
- WAIVER_REASONS
45
- };
1
+ const DEFAULT_USER_ROLE = 'ICS';
2
+
3
+ const WAIVE_ACTIONS = {
4
+ WAIVE: 'ignored',
5
+ RETRACT: 'notIgnored'
6
+ };
7
+
8
+ const WAIVER_REASONS = {
9
+ BUSINESS_DECISION: 'Business_Decision',
10
+ NO_EXPOSURE: 'No_Exposure',
11
+ EXECUTIVE_APPROVAL: 'Executive_Approval'
12
+ };
13
+
14
+ function WaiveRequestModel({
15
+ userId,
16
+ contractorId,
17
+ auditId,
18
+ waiverReason,
19
+ remarks = '',
20
+ userRole = DEFAULT_USER_ROLE
21
+ }) {
22
+ this.auditorContractorId = auditId;
23
+ this.contractorId = contractorId;
24
+ this.userId = userId;
25
+ this.waiverReason = waiverReason;
26
+ this.remarks = remarks;
27
+
28
+ this.userRole = userRole;
29
+ this.status = WAIVE_ACTIONS.WAIVE;
30
+ }
31
+
32
+ function RetractRequestModel({ userId, contractorId, auditId, userRole = DEFAULT_USER_ROLE }) {
33
+ this.auditorContractorId = auditId;
34
+ this.contractorId = contractorId;
35
+ this.userId = userId;
36
+ this.userRole = userRole;
37
+ this.status = WAIVE_ACTIONS.RETRACT;
38
+ }
39
+
40
+ module.exports = {
41
+ WaiveRequestModel,
42
+ RetractRequestModel,
43
+ WAIVE_ACTIONS,
44
+ WAIVER_REASONS
45
+ };
@@ -1,218 +1,173 @@
1
- const { AUDIT_ENTITY_STATUSES, DEFAULT_POLICY_ID, VALID_SCORES } = require('../consts/audit');
2
-
3
- const emptyValue = '';
4
-
5
- const getValueBySelection = selection => {
6
- return ['Yes', 'No', 'Empty', 'Claims'].includes(selection) ? emptyValue : selection;
7
- };
8
-
9
- const getDateInApiFormat = date => {
10
- return dateTimeModule.convertDateToNewFormat(
11
- date,
12
- dateTimeModule.formats.dayMonthYear,
13
- dateTimeModule.formats.numericMonthDayYear
14
- );
15
- };
16
-
17
- const getAttributeKey = attribute => {
18
- return specialAttributes[attribute] || attribute;
19
- };
20
-
21
- const getAuditEntities = async (recordId, auditData, auditorContext) => {
22
- const requirementDetailsForAuditResponse = await auditServices.getRequirementDetailsForAudit(recordId, auditorContext);
23
- const requirement = requirementDetailsForAuditResponse.data;
24
-
25
- const auditEntities = [];
26
- auditData.forEach(auditEntity => auditEntities.push(
27
- createAuditEntity(requirement, { ... auditEntity }))
28
- );
29
- return auditEntities;
30
- };
31
-
32
- const createAuditEntity = (
33
- requirement, {
34
- policyName = null,
35
- attributeName = null,
36
- value = emptyValue,
37
- status = emptyValue
38
- }) => {
39
- const policyId = getPolicyId(policyName, requirement);
40
- const auditEntityModel = new auditModels.AuditEntityModel(policyId, attributeName, status, value);
41
- return auditEntityModel;
42
- };
43
-
44
- const getPolicyId = (policyName, requirement) => {
45
- if (!policyName || policyName === 'Certificate of Insurance') {
46
- return DEFAULT_POLICY_ID;
47
- }
48
-
49
- const policy = requirement.policies.find(policy => policy.name === policyName);
50
-
51
- if (!policy) {
52
- let policiesList = emptyValue;
53
- requirement.policies.forEach(policy => policiesList += `${policy.name},`);
54
-
55
- throw Error(`Policy '${policyName}' not found in the Requirement. List: ${policiesList.slice(0, -1)}`);
56
- }
57
-
58
- return policy.id;
59
- };
60
-
61
- const getAuditRequestModel = (metaData, auditEntities) => {
62
- const {
63
- accountId = null,
64
- projectId = null,
65
- requirementId = null,
66
- contractorId = null,
67
- certificateId = null,
68
- auditorId = null,
69
- auditStatus = null,
70
- isReaudit = false,
71
- isProjectOnboarding = false,
72
- shouldSendNotificationToPM = false,
73
- auditDates = {}
74
- } = metaData;
75
-
76
- const auditDatesModel = new auditModels.AuditDatesModel(
77
- auditDates.contractorId,
78
- auditDates.contractorDateModified,
79
- auditDates.dateStartedAudit,
80
- auditDates.contractorOverrideDateModified,
81
- auditDates.contractCreateDate
82
- );
83
-
84
- const auditRequestModel = new auditModels.AuditRequestModel(
85
- accountId,
86
- projectId,
87
- requirementId,
88
- contractorId,
89
- certificateId,
90
- auditorId,
91
- auditEntities,
92
- isReaudit,
93
- isProjectOnboarding,
94
- shouldSendNotificationToPM,
95
- auditDatesModel,
96
- auditStatus
97
- );
98
-
99
- return auditRequestModel;
100
- };
101
-
102
- const getParsedConfig = function(config) {
103
- const automationInfra = require('../../../infrastructure/automation/automationInfra');
104
- config = automationInfra.cloneObject(config);
105
- const auditDataArr = [];
106
- for (const field in config) {
107
- if (!config.hasOwnProperty(field)) {
108
- continue;
109
- }
110
-
111
- if (typeof config[field] === 'object' && !Array.isArray(config[field])) {
112
- const attributes = config[field];
113
- for (const attributeName in attributes) {
114
- if (attributeName === 'Policy Expiry') {
115
- attributes[attributeName] = getDateInApiFormat(attributes[attributeName]);
116
- }
117
-
118
- const selection = { policyName: field };
119
-
120
- // Special attribute names switch
121
- switch (attributeName) {
122
- case 'Occur':
123
- const occurKeys = getAttributeKey(attributeName);
124
- selection.attributeName = occurKeys[field];
125
- break;
126
- default:
127
- selection.attributeName = getAttributeKey(attributeName);
128
- break;
129
- }
130
-
131
- if (Array.isArray(attributes[attributeName])) {
132
- selection.status = AUDIT_ENTITY_STATUSES[ attributes[attributeName][0] ];
133
- selection.value = attributes[attributeName][1].replace('$', emptyValue);
134
- } else {
135
- // Special statuses switch
136
- switch (selection.attributeName) {
137
- case getAttributeKey('Policy Number'):
138
- selection.status = emptyValue;
139
- break;
140
- case getAttributeKey('Policy Expiry'):
141
- selection.status = AUDIT_ENTITY_STATUSES.YES;
142
- break;
143
- default:
144
- selection.status = AUDIT_ENTITY_STATUSES[ attributes[attributeName] ];
145
- break;
146
- }
147
-
148
- selection.value = getValueBySelection(attributes[attributeName]);
149
- }
150
-
151
- auditDataArr.push(selection);
152
- }
153
- } else {
154
- if (field === 'Certificate issue date') {
155
- config[field] = getDateInApiFormat(config[field]);
156
- }
157
-
158
- const selection = { attributeName: getAttributeKey(field) };
159
- certificateEndorsmentsList.includes(field) && (selection.policyName = field);
160
-
161
- if (Array.isArray(config[field])) {
162
- selection.status = AUDIT_ENTITY_STATUSES[ config[field][0] ];
163
- selection.value = config[field][1]; // Ok to be undefined
164
- } else {
165
- selection.status = AUDIT_ENTITY_STATUSES[ config[field] ] || AUDIT_ENTITY_STATUSES.YES;
166
- selection.value = getValueBySelection(config[field]);
167
- }
168
-
169
- if (field === 'AM Score') {
170
- selection.status = VALID_SCORES.includes(selection.value) ? AUDIT_ENTITY_STATUSES.YES : AUDIT_ENTITY_STATUSES.NO;
171
- }
172
-
173
- auditDataArr.push(selection);
174
- }
175
- }
176
- return auditDataArr;
177
- };
178
-
179
- module.exports = {
180
- getAuditEntities,
181
- getAuditRequestModel,
182
- getParsedConfig
183
- };
184
-
185
- const certificateEndorsmentsList = [
186
- 'Waiver Of Subrogation',
187
- 'Certificate Holder',
188
- 'Additional Information',
189
- 'Additional Insured',
190
- 'Agreement'
191
- ];
192
-
193
- const specialAttributes = {
194
- 'Certificate issue date': 'certIssueDate',
195
- 'Cancellation Terms': 'cancellationTerms',
196
- 'COI authentication': 'COIauthentication',
197
- 'AM Score': 'AMBestRating',
198
- 'Signature': 'signature',
199
-
200
- 'Insured Address': 'Insured Address',
201
- 'Insured Name': 'Insured Name',
202
-
203
- 'Additional Information': 'additionalInformation',
204
- 'Waiver Of Subrogation': 'waiverofsubrogation',
205
- 'Additional Insured': 'additionalInsured',
206
- 'Certificate Holder': 'certificateHolder',
207
-
208
- 'Coverage Exists': 'coverageexists',
209
- 'Coverage exists': 'coverageexists',
210
- 'Policy Number': 'policynumber',
211
- 'Policy Expiry': 'expirydate',
212
- 'Per Occur': 'PerOccur',
213
-
214
- 'Occur': {
215
- 'Excess Liability': 'EXoccur',
216
- 'Umbrella': 'UMoccur'
217
- }
218
- };
1
+ const { AUDIT_ENTITY_STATUSES, DEFAULT_POLICY_ID, VALID_SCORES } = require('../consts/audit');
2
+ const { isObject, isArray } = require('../../../../common/utils/dataTypeUtils');
3
+ const timeUtils = require('../../../../common/utils/timeUtils');
4
+ const auditModels = require('../models/audit/audit.model');
5
+ const auth = require('../../auth');
6
+
7
+ const emptyValue = '';
8
+
9
+ const getValueBySelection = selection => {
10
+ return ['Yes', 'No', 'Empty', 'Claims'].includes(selection) ? emptyValue : selection;
11
+ };
12
+
13
+ const getDateInApiFormat = date => {
14
+ return timeUtils.convertDateToNewFormat(
15
+ date,
16
+ timeUtils.formats.dayMonthYear,
17
+ timeUtils.formats.numericMonthDayYear
18
+ );
19
+ };
20
+
21
+ const getAttributeKey = attribute => {
22
+ return specialAttributes[attribute] || attribute;
23
+ };
24
+
25
+ const getPolicyId = (policyName, requirement) => {
26
+ if (!policyName || policyName === 'Certificate of Insurance') {
27
+ return DEFAULT_POLICY_ID;
28
+ }
29
+
30
+ const policy = requirement.policies.find(policy => policy.name === policyName);
31
+
32
+ if (!policy) {
33
+ let policiesList = emptyValue;
34
+ requirement.policies.forEach(policy => policiesList += `${policy.name},`);
35
+
36
+ throw Error(`Policy '${policyName}' not found in the Requirement. List: ${policiesList.slice(0, -1)}`);
37
+ }
38
+
39
+ return policy.id;
40
+ };
41
+
42
+ const getParsedConfig = function(config) {
43
+ const auditDataArr = [];
44
+ for (const field in config) {
45
+ if (!config.hasOwnProperty(field)) {
46
+ continue;
47
+ }
48
+
49
+ if (isObject(config[field])) {
50
+ const attributes = config[field];
51
+ for (const attributeName in attributes) {
52
+ if (attributeName === 'Policy Expiry') {
53
+ attributes[attributeName] = getDateInApiFormat(attributes[attributeName]);
54
+ }
55
+
56
+ const selection = { policyName: field };
57
+
58
+ // Special attribute names switch
59
+ switch (attributeName) {
60
+ case 'Occur':
61
+ const occurKeys = getAttributeKey(attributeName);
62
+ selection.attributeName = occurKeys[field];
63
+ break;
64
+ default:
65
+ selection.attributeName = getAttributeKey(attributeName);
66
+ break;
67
+ }
68
+
69
+ if (isArray(attributes[attributeName])) {
70
+ selection.status = AUDIT_ENTITY_STATUSES[ attributes[attributeName][0] ];
71
+ selection.value = attributes[attributeName][1].replace('$', emptyValue);
72
+ } else {
73
+ // Special statuses switch
74
+ switch (selection.attributeName) {
75
+ case getAttributeKey('Policy Number'):
76
+ selection.status = emptyValue;
77
+ break;
78
+ case getAttributeKey('Policy Expiry'):
79
+ selection.status = AUDIT_ENTITY_STATUSES.YES;
80
+ break;
81
+ default:
82
+ selection.status = AUDIT_ENTITY_STATUSES[ (attributes[attributeName]).toUpperCase() ];
83
+ break;
84
+ }
85
+
86
+ selection.value = getValueBySelection(attributes[attributeName]);
87
+ }
88
+
89
+ auditDataArr.push(selection);
90
+ }
91
+ } else {
92
+ if (field === 'Certificate issue date') {
93
+ config[field] = getDateInApiFormat(config[field]);
94
+ }
95
+
96
+ const selection = { attributeName: getAttributeKey(field) };
97
+ certificateEndorsmentsList.includes(field) && (selection.policyName = field);
98
+
99
+ if (isArray(config[field])) {
100
+ selection.status = AUDIT_ENTITY_STATUSES[ config[field][0] ];
101
+ selection.value = config[field][1]; // Ok to be undefined
102
+ } else {
103
+ selection.status = AUDIT_ENTITY_STATUSES[ config[field] ] || AUDIT_ENTITY_STATUSES.YES;
104
+ selection.value = getValueBySelection(config[field]);
105
+ }
106
+
107
+ if (field === 'AM Score') {
108
+ selection.status = VALID_SCORES.includes(selection.value) ? AUDIT_ENTITY_STATUSES.YES : AUDIT_ENTITY_STATUSES.NO;
109
+ }
110
+
111
+ auditDataArr.push(selection);
112
+ }
113
+ }
114
+ return auditDataArr;
115
+ };
116
+
117
+ const createAuditEntity = (
118
+ requirement, {
119
+ policyName = null,
120
+ attributeName = null,
121
+ value = emptyValue,
122
+ status = emptyValue
123
+ }) => {
124
+ const policyId = getPolicyId(policyName, requirement);
125
+ const auditEntityModel = new auditModels.AuditEntityModel(policyId, attributeName, status, value);
126
+ return auditEntityModel;
127
+ };
128
+
129
+ const getAuditorId = () => {
130
+ return auth.services.getAuditorId();
131
+ };
132
+
133
+ module.exports = {
134
+ getParsedConfig,
135
+ getPolicyId,
136
+ createAuditEntity,
137
+ getAuditorId
138
+ };
139
+
140
+ const certificateEndorsmentsList = [
141
+ 'Waiver Of Subrogation',
142
+ 'Certificate Holder',
143
+ 'Additional Information',
144
+ 'Additional Insured',
145
+ 'Agreement'
146
+ ];
147
+
148
+ const specialAttributes = {
149
+ 'Certificate issue date': 'certIssueDate',
150
+ 'Cancellation Terms': 'cancellationTerms',
151
+ 'COI authentication': 'COIauthentication',
152
+ 'AM Score': 'AMBestRating',
153
+ 'Signature': 'signature',
154
+
155
+ 'Insured Address': 'Insured Address',
156
+ 'Insured Name': 'Insured Name',
157
+
158
+ 'Additional Information': 'additionalInformation',
159
+ 'Waiver Of Subrogation': 'waiverofsubrogation',
160
+ 'Additional Insured': 'additionalInsured',
161
+ 'Certificate Holder': 'certificateHolder',
162
+
163
+ 'Coverage Exists': 'coverageexists',
164
+ 'Coverage exists': 'coverageexists',
165
+ 'Policy Number': 'policynumber',
166
+ 'Policy Expiry': 'expirydate',
167
+ 'Per Occur': 'PerOccur',
168
+
169
+ 'Occur': {
170
+ 'Excess Liability': 'EXoccur',
171
+ 'Umbrella': 'UMoccur'
172
+ }
173
+ };