@getjones/test-infra 5.2.14 → 5.2.16

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 (296) hide show
  1. package/eslint.config.mjs +156 -156
  2. package/package.json +43 -43
  3. package/src/common/commonFlows/auth/auth.js +95 -95
  4. package/src/common/commonFlows/index.js +5 -5
  5. package/src/common/commonFlows/records/records.js +452 -452
  6. package/src/common/commonFlows/users/users.js +15 -15
  7. package/src/common/consts/accountSettings.js +112 -112
  8. package/src/common/consts/activationStatuses.js +6 -6
  9. package/src/common/consts/analysisStatuses.js +7 -7
  10. package/src/common/consts/autocomplete.js +10 -10
  11. package/src/common/consts/constantsForRecordsSortingAndFilters.js +49 -49
  12. package/src/common/consts/dashboardCharts.js +18 -18
  13. package/src/common/consts/homepage/AttentionTab.js +6 -6
  14. package/src/common/consts/homepage/sortOptions.js +19 -19
  15. package/src/common/consts/projectSettings.js +28 -28
  16. package/src/common/consts/recordTypes.js +5 -5
  17. package/src/common/consts/requirementActions.js +10 -10
  18. package/src/common/consts/s3FileTypes.js +12 -12
  19. package/src/common/consts/userRoles.js +21 -21
  20. package/src/common/consts/userTypes.js +16 -16
  21. package/src/common/errorCodes.js +13 -13
  22. package/src/common/httpResponseStatusCodes.json +19 -19
  23. package/src/common/httpResponseTypes.json +2 -2
  24. package/src/common/requests/apiKeyAuth/requests.js +45 -45
  25. package/src/common/requests/cookieAuth/requests.js +40 -40
  26. package/src/common/requests/internalAuth/requests.js +48 -48
  27. package/src/common/requests/requestHandlers.js +112 -112
  28. package/src/common/utils/arrayUtils.js +19 -19
  29. package/src/common/utils/complianceUtil.js +114 -114
  30. package/src/common/utils/configsUtil.js +22 -22
  31. package/src/common/utils/dataTypeUtils.js +41 -41
  32. package/src/common/utils/numberUtils.js +22 -22
  33. package/src/common/utils/objectUtils.js +102 -102
  34. package/src/common/utils/timeUtils.js +202 -202
  35. package/src/common/validations/typeValidations.js +36 -36
  36. package/src/defaults/configs/attributes.js +170 -170
  37. package/src/defaults/configs/auditConfigs.js +129 -129
  38. package/src/defaults/configs/coverage.js +144 -144
  39. package/src/defaults/configs/polices.js +28 -28
  40. package/src/defaults/configs/requirement.js +218 -218
  41. package/src/defaults/index.js +7 -7
  42. package/src/env.js +58 -58
  43. package/src/factory/globalRecord/globalRecord.js +43 -43
  44. package/src/factory/index.js +8 -8
  45. package/src/factory/records/records.js +295 -295
  46. package/src/factory/users/users.js +70 -70
  47. package/src/index.js +118 -118
  48. package/src/reporters/mochaReporter.js +273 -273
  49. package/src/saas/internal-api/accountDirectory/api/accountDirectory.api.js +152 -152
  50. package/src/saas/internal-api/accountDirectory/api/accountDirectory.service.js +576 -576
  51. package/src/saas/internal-api/accountDirectory/consts/accountDirectory.consts.js +75 -75
  52. package/src/saas/internal-api/accountDirectory/index.js +5 -5
  53. package/src/saas/internal-api/accountDirectory/models/accountDirectory.models.js +172 -172
  54. package/src/saas/internal-api/accounts/api/core/accounts.core.api.js +54 -54
  55. package/src/saas/internal-api/accounts/api/core/accounts.core.service.js +114 -114
  56. package/src/saas/internal-api/accounts/api/emailCustomization/accounts.email.customizations.api.js +29 -29
  57. package/src/saas/internal-api/accounts/api/emailCustomization/accounts.email.customizations.service.js +60 -60
  58. package/src/saas/internal-api/accounts/api/emailCustomization/consts.js +8 -8
  59. package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.api.js +54 -54
  60. package/src/saas/internal-api/accounts/api/openapi/accounts.openapi.service.js +67 -67
  61. package/src/saas/internal-api/accounts/api/settings/settings.api.js +21 -21
  62. package/src/saas/internal-api/accounts/api/settings/settings.service.js +58 -58
  63. package/src/saas/internal-api/accounts/consts/consts.js +8 -8
  64. package/src/saas/internal-api/accounts/index.js +22 -22
  65. package/src/saas/internal-api/accounts/models/core/create.account.model.js +16 -16
  66. package/src/saas/internal-api/accounts/models/settings/update.settings.model.js +110 -110
  67. package/src/saas/internal-api/accounts/utils/utils.js +60 -60
  68. package/src/saas/internal-api/agreement/api/agreement.api.js +39 -39
  69. package/src/saas/internal-api/agreement/api/agreement.service.js +121 -121
  70. package/src/saas/internal-api/agreement/consts/consts.js +11 -11
  71. package/src/saas/internal-api/agreement/index.js +12 -12
  72. package/src/saas/internal-api/agreement/models/create.agreement.model.js +12 -12
  73. package/src/saas/internal-api/agreement/models/createAgreementByAuditorModel.js +11 -11
  74. package/src/saas/internal-api/agreement/models/createAgreementByPMModel.js +13 -13
  75. package/src/saas/internal-api/auditCustomerRules/api/customer.rules.api.js +49 -49
  76. package/src/saas/internal-api/auditCustomerRules/api/customer.rules.service.js +121 -121
  77. package/src/saas/internal-api/auditCustomerRules/consts/customer.rule.js +40 -40
  78. package/src/saas/internal-api/auditCustomerRules/index.js +7 -7
  79. package/src/saas/internal-api/auditCustomerRules/models/customer.rule.model.js +55 -55
  80. package/src/saas/internal-api/auditCustomerRules/utils/customer.rule.util.js +70 -70
  81. package/src/saas/internal-api/auditNotes/api/audit.notes.api.js +40 -40
  82. package/src/saas/internal-api/auditNotes/api/audit.notes.service.js +116 -116
  83. package/src/saas/internal-api/auditNotes/index.js +4 -4
  84. package/src/saas/internal-api/auditNotes/models/audit.note.model.js +32 -32
  85. package/src/saas/internal-api/auditorComments/api/auditor.comments.api.js +20 -20
  86. package/src/saas/internal-api/auditorComments/api/auditor.comments.service.js +27 -27
  87. package/src/saas/internal-api/auditorComments/consts/auditor.comment.js +16 -16
  88. package/src/saas/internal-api/auditorComments/index.js +5 -5
  89. package/src/saas/internal-api/auditorComments/models/auditor.comment.model.js +40 -40
  90. package/src/saas/internal-api/auth/api/auth.api.js +78 -78
  91. package/src/saas/internal-api/auth/api/auth.service.js +217 -217
  92. package/src/saas/internal-api/auth/index.js +3 -3
  93. package/src/saas/internal-api/certificial/api/certificial.api.js +15 -15
  94. package/src/saas/internal-api/certificial/api/certificial.service.js +24 -24
  95. package/src/saas/internal-api/certificial/consts.js +8 -8
  96. package/src/saas/internal-api/certificial/index.js +4 -4
  97. package/src/saas/internal-api/coi/api/coi.api.js +76 -76
  98. package/src/saas/internal-api/coi/api/coi.service.js +104 -104
  99. package/src/saas/internal-api/coi/consts/{uploaderStatuses.js → coiUploaderTypes.js} +9 -9
  100. package/src/saas/internal-api/coi/consts/duplicateHandling.js +7 -7
  101. package/src/saas/internal-api/coi/consts/hashes.js +5 -5
  102. package/src/saas/internal-api/coi/consts/uploaderTypes.js +3 -3
  103. package/src/saas/internal-api/coi/index.js +17 -17
  104. package/src/saas/internal-api/coi/models/Combine.last.two.cois.model.js +25 -25
  105. package/src/saas/internal-api/coi/models/submit.coi.batch.model.js +23 -23
  106. package/src/saas/internal-api/coi/models/submit.coi.model.js +23 -23
  107. package/src/saas/internal-api/coi/utils/utils.js +186 -185
  108. package/src/saas/internal-api/compliance/api/amBestRating/am.best.rating.api.js +12 -12
  109. package/src/saas/internal-api/compliance/api/amBestRating/am.best.rating.service.js +14 -14
  110. package/src/saas/internal-api/compliance/api/audit/aiAudit/aiAudit.api.js +63 -63
  111. package/src/saas/internal-api/compliance/api/audit/aiAudit/aiAudit.service.js +99 -99
  112. package/src/saas/internal-api/compliance/api/audit/audit.api.js +124 -124
  113. package/src/saas/internal-api/compliance/api/audit/audit.service.js +390 -390
  114. package/src/saas/internal-api/compliance/api/complianceSnapshot/compliance.snapshot.api.js +32 -32
  115. package/src/saas/internal-api/compliance/api/complianceSnapshot/compliance.snapshot.service.js +73 -73
  116. package/src/saas/internal-api/compliance/api/convert/convert.api.js +12 -12
  117. package/src/saas/internal-api/compliance/api/convert/convert.service.js +7 -7
  118. package/src/saas/internal-api/compliance/api/coverage/coverage.api.js +33 -33
  119. package/src/saas/internal-api/compliance/api/coverage/coverage.service.js +46 -46
  120. package/src/saas/internal-api/compliance/api/overrideGap/override.gap.api.js +86 -86
  121. package/src/saas/internal-api/compliance/api/overrideGap/override.gap.service.js +300 -300
  122. package/src/saas/internal-api/compliance/consts/audit.js +130 -130
  123. package/src/saas/internal-api/compliance/consts/overrideGapRequest/override.gap.request.js +7 -7
  124. package/src/saas/internal-api/compliance/index.js +41 -41
  125. package/src/saas/internal-api/compliance/models/audit/audit.model.js +109 -109
  126. package/src/saas/internal-api/compliance/models/overrideGapRequest/override.gap.request.model.js +16 -16
  127. package/src/saas/internal-api/compliance/models/waive/waive.model.js +112 -112
  128. package/src/saas/internal-api/compliance/utils/auditUtil.js +308 -308
  129. package/src/saas/internal-api/compliance/utils/coverageUtil.js +45 -45
  130. package/src/saas/internal-api/contractors/api/contractors.api.js +251 -251
  131. package/src/saas/internal-api/contractors/api/contractors.service.js +482 -482
  132. package/src/saas/internal-api/contractors/consts/consts.js +6 -6
  133. package/src/saas/internal-api/contractors/index.js +8 -8
  134. package/src/saas/internal-api/contractors/models/assign.requirement.model.js +11 -11
  135. package/src/saas/internal-api/contractors/models/edit.contractor.model.js +73 -73
  136. package/src/saas/internal-api/contractors/models/link.request.model.js +10 -10
  137. package/src/saas/internal-api/contractors/models/verification.contractor.model.js +29 -29
  138. package/src/saas/internal-api/contractors/utils.js +25 -25
  139. package/src/saas/internal-api/customTags/api/customTags.api.js +47 -47
  140. package/src/saas/internal-api/customTags/api/customTags.service.js +96 -96
  141. package/src/saas/internal-api/customTags/index.js +4 -4
  142. package/src/saas/internal-api/customTags/models/customTagsModels.js +17 -17
  143. package/src/saas/internal-api/dashboard/api/recordList.api.js +38 -38
  144. package/src/saas/internal-api/dashboard/api/recordList.service.js +60 -60
  145. package/src/saas/internal-api/dashboard/index.js +5 -5
  146. package/src/saas/internal-api/dashboard/models/dashboard.filter.criteria.model.js +38 -38
  147. package/src/saas/internal-api/dbEmails/api/db.emails.api.js +25 -25
  148. package/src/saas/internal-api/dbEmails/api/db.emails.service.js +209 -209
  149. package/src/saas/internal-api/dbEmails/consts/consts.js +66 -66
  150. package/src/saas/internal-api/dbEmails/index.js +6 -6
  151. package/src/saas/internal-api/dbEmails/models/db.emails.model.js +22 -22
  152. package/src/saas/internal-api/dbEmails/utils/util.js +82 -82
  153. package/src/saas/internal-api/emailCustomization/api/email.customization.api.js +26 -26
  154. package/src/saas/internal-api/emailCustomization/api/email.customization.service.js +50 -50
  155. package/src/saas/internal-api/emailCustomization/index.js +3 -3
  156. package/src/saas/internal-api/fileScan/api/file.scan.api.js +14 -14
  157. package/src/saas/internal-api/fileScan/api/file.scan.service.js +35 -35
  158. package/src/saas/internal-api/fileScan/index.js +3 -3
  159. package/src/saas/internal-api/fileScan/models/update.scan.status.model.js +13 -13
  160. package/src/saas/internal-api/globalRecord/api/global.record.api.js +95 -95
  161. package/src/saas/internal-api/globalRecord/api/global.record.service.js +112 -112
  162. package/src/saas/internal-api/globalRecord/consts.js +20 -20
  163. package/src/saas/internal-api/globalRecord/index.js +6 -6
  164. package/src/saas/internal-api/globalRecord/models/global.record.model.js +60 -60
  165. package/src/saas/internal-api/globalRecord/utils/util.js +161 -161
  166. package/src/saas/internal-api/homepageCharts/api/charts.api.js +12 -12
  167. package/src/saas/internal-api/homepageCharts/api/charts.service.js +7 -7
  168. package/src/saas/internal-api/homepageCharts/index.js +3 -3
  169. package/src/saas/internal-api/notificationCenter/api/notification.center.api.js +32 -32
  170. package/src/saas/internal-api/notificationCenter/api/notification.center.service.js +49 -49
  171. package/src/saas/internal-api/notificationCenter/consts.js +9 -9
  172. package/src/saas/internal-api/notificationCenter/index.js +4 -4
  173. package/src/saas/internal-api/outlook/api/outlook.api.js +14 -14
  174. package/src/saas/internal-api/outlook/api/outlook.service.js +14 -14
  175. package/src/saas/internal-api/outlook/index.js +3 -3
  176. package/src/saas/internal-api/policyFile/api/policy.file.api.js +43 -43
  177. package/src/saas/internal-api/policyFile/api/policy.file.service.js +117 -117
  178. package/src/saas/internal-api/policyFile/consts.js +21 -21
  179. package/src/saas/internal-api/policyFile/index.js +11 -11
  180. package/src/saas/internal-api/policyFile/models/create.policy.file.model.js +11 -11
  181. package/src/saas/internal-api/policyFile/models/set.publish.flag.to.policy.model.js +13 -13
  182. package/src/saas/internal-api/projects/api/core/projects.api.js +39 -39
  183. package/src/saas/internal-api/projects/api/core/projects.service.js +77 -77
  184. package/src/saas/internal-api/projects/api/settings/project.settings.api.js +18 -18
  185. package/src/saas/internal-api/projects/api/settings/project.settings.service.js +35 -35
  186. package/src/saas/internal-api/projects/consts/defaultProject.js +3 -3
  187. package/src/saas/internal-api/projects/index.js +24 -24
  188. package/src/saas/internal-api/projects/models/core/create.project.model.js +41 -41
  189. package/src/saas/internal-api/projects/models/core/update.project.model.js +47 -47
  190. package/src/saas/internal-api/projects/models/settings/update.project.settings.model.js +56 -56
  191. package/src/saas/internal-api/projects/utils/utils.js +159 -159
  192. package/src/saas/internal-api/recordHub/api/record.hub.api.js +20 -20
  193. package/src/saas/internal-api/recordHub/api/record.hub.service.js +86 -86
  194. package/src/saas/internal-api/recordHub/index.js +3 -3
  195. package/src/saas/internal-api/recordNotes/api/record.notes.api.js +38 -38
  196. package/src/saas/internal-api/recordNotes/api/record.notes.service.js +56 -56
  197. package/src/saas/internal-api/recordNotes/api/record.notes.utils.js +12 -12
  198. package/src/saas/internal-api/recordNotes/index.js +3 -3
  199. package/src/saas/internal-api/relatedDocs/api/related.docs.api.js +98 -98
  200. package/src/saas/internal-api/relatedDocs/api/related.docs.service.js +180 -180
  201. package/src/saas/internal-api/relatedDocs/index.js +4 -4
  202. package/src/saas/internal-api/relatedDocs/models/related.doc.model.js +36 -36
  203. package/src/saas/internal-api/reports/api/reports.api.js +56 -56
  204. package/src/saas/internal-api/reports/api/reports.service.js +68 -68
  205. package/src/saas/internal-api/reports/consts/consts.js +71 -71
  206. package/src/saas/internal-api/reports/index.js +15 -15
  207. package/src/saas/internal-api/reports/models/report.model.js +27 -27
  208. package/src/saas/internal-api/requests/api/requests.api.js +132 -132
  209. package/src/saas/internal-api/requests/api/requests.service.js +315 -315
  210. package/src/saas/internal-api/requests/index.js +21 -21
  211. package/src/saas/internal-api/requests/models/create.request.model.js +39 -39
  212. package/src/saas/internal-api/requests/models/draft.request.criteria.model.js +18 -18
  213. package/src/saas/internal-api/requests/models/draft.request.report.model.js +14 -14
  214. package/src/saas/internal-api/requests/models/edit.request.model.js +31 -31
  215. package/src/saas/internal-api/requests/models/homepageRequestCriteriaModel.js +19 -19
  216. package/src/saas/internal-api/requests/models/requestListCriteriaModel.js +17 -17
  217. package/src/saas/internal-api/requests/models/tenant.request.model.js +9 -9
  218. package/src/saas/internal-api/requests/utils.js +16 -16
  219. package/src/saas/internal-api/requestsTable/api/requests.table.api.js +20 -20
  220. package/src/saas/internal-api/requestsTable/api/requests.table.service.js +14 -14
  221. package/src/saas/internal-api/requestsTable/index.js +3 -3
  222. package/src/saas/internal-api/requirements/api/lease/lease.api.js +74 -74
  223. package/src/saas/internal-api/requirements/api/lease/lease.service.js +167 -167
  224. package/src/saas/internal-api/requirements/api/requirements.api.js +65 -65
  225. package/src/saas/internal-api/requirements/api/requirements.service.js +198 -198
  226. package/src/saas/internal-api/requirements/consts/attributeTypes.json +8 -8
  227. package/src/saas/internal-api/requirements/consts/consts.js +22 -22
  228. package/src/saas/internal-api/requirements/index.js +22 -22
  229. package/src/saas/internal-api/requirements/models/create.requirement.model.js +17 -17
  230. package/src/saas/internal-api/requirements/models/extraction.request.model.js +16 -16
  231. package/src/saas/internal-api/requirements/models/policy.model.js +35 -35
  232. package/src/saas/internal-api/requirements/models/tab.extraction.request.model.js +14 -14
  233. package/src/saas/internal-api/requirements/models/update.requirement.model.js +19 -19
  234. package/src/saas/internal-api/requirements/utils/utils.js +129 -129
  235. package/src/saas/internal-api/sampleCoi/api/sample.coi.api.js +15 -15
  236. package/src/saas/internal-api/sampleCoi/api/sample.coi.service.js +48 -48
  237. package/src/saas/internal-api/sampleCoi/consts/consts.js +22 -22
  238. package/src/saas/internal-api/sampleCoi/index.js +4 -4
  239. package/src/saas/internal-api/schedulerJobRun/api/scheduler.job.run.api.js +31 -31
  240. package/src/saas/internal-api/schedulerJobRun/api/scheduler.job.run.service.js +56 -56
  241. package/src/saas/internal-api/schedulerJobRun/index.js +3 -3
  242. package/src/saas/internal-api/serviceArea/api/coordinates.api.js +12 -12
  243. package/src/saas/internal-api/serviceArea/api/coordinates.service.js +7 -7
  244. package/src/saas/internal-api/serviceArea/index.js +4 -4
  245. package/src/saas/internal-api/serviceArea/utils/utils.js +8 -8
  246. package/src/saas/internal-api/tableOfContents/api/table.of.contents.api.js +37 -37
  247. package/src/saas/internal-api/tableOfContents/api/table.of.contents.service.js +19 -19
  248. package/src/saas/internal-api/tableOfContents/index.js +3 -3
  249. package/src/saas/internal-api/tabs/api/tabs.api.js +32 -32
  250. package/src/saas/internal-api/tabs/api/tabs.service.js +60 -60
  251. package/src/saas/internal-api/tabs/index.js +3 -3
  252. package/src/saas/internal-api/tabs/models/tabs.model.js +19 -19
  253. package/src/saas/internal-api/thread-scheduler/runner.js +86 -86
  254. package/src/saas/internal-api/thread-scheduler/schedulerJobs.js +10 -10
  255. package/src/saas/internal-api/uploadFiles/api/upload.file.api.js +49 -49
  256. package/src/saas/internal-api/uploadFiles/api/upload.file.service.js +176 -176
  257. package/src/saas/internal-api/uploadFiles/consts.js +36 -36
  258. package/src/saas/internal-api/uploadFiles/index.js +5 -5
  259. package/src/saas/internal-api/uploadFiles/utils.js +34 -34
  260. package/src/saas/internal-api/users/api/tenantApp/tenant.app.api.js +38 -38
  261. package/src/saas/internal-api/users/api/tenantApp/tenant.app.service.js +109 -109
  262. package/src/saas/internal-api/users/api/users.api.js +158 -158
  263. package/src/saas/internal-api/users/api/users.service.js +363 -363
  264. package/src/saas/internal-api/users/index.js +17 -17
  265. package/src/saas/internal-api/users/models/create.inner.system.user.model.js +18 -18
  266. package/src/saas/internal-api/users/models/notification.settings.model.js +15 -15
  267. package/src/saas/internal-api/users/models/tenant.user.model.js +11 -11
  268. package/src/saas/internal-api/users/models/users.model.js +43 -43
  269. package/src/saas/internal-api/users/utils/util.js +50 -50
  270. package/src/saas/internal-api/vendorProfile/api/vendor.profile.api.js +26 -26
  271. package/src/saas/internal-api/vendorProfile/api/vendor.profile.service.js +19 -19
  272. package/src/saas/internal-api/vendorProfile/index.js +3 -3
  273. package/src/saas/openapi/accounts/accounts.api.js +17 -17
  274. package/src/saas/openapi/accounts/accounts.service.js +11 -11
  275. package/src/saas/openapi/coi/coi.api.js +35 -35
  276. package/src/saas/openapi/coi/coi.service.js +53 -53
  277. package/src/saas/openapi/projects/projects.api.js +83 -83
  278. package/src/saas/openapi/projects/projects.service.js +89 -89
  279. package/src/saas/openapi/relatedDocs/related.docs.api.js +30 -30
  280. package/src/saas/openapi/relatedDocs/related.docs.service.js +56 -56
  281. package/src/saas/openapi/requests/index.js +7 -7
  282. package/src/saas/openapi/requests/models/invite.request.model.js +42 -42
  283. package/src/saas/openapi/requests/models/update.request.model.js +37 -37
  284. package/src/saas/openapi/requests/requests.api.js +93 -93
  285. package/src/saas/openapi/requests/requests.service.js +100 -100
  286. package/src/saas/openapi/requirements/index.js +6 -6
  287. package/src/saas/openapi/requirements/models/copy.requirement.model.js +10 -10
  288. package/src/saas/openapi/requirements/requirements.api.js +41 -41
  289. package/src/saas/openapi/requirements/requirements.service.js +61 -61
  290. package/src/saas/openapi/tabs/index.js +6 -6
  291. package/src/saas/openapi/tabs/models/create.tab.model.js +6 -6
  292. package/src/saas/openapi/tabs/tabs.api.js +27 -27
  293. package/src/saas/openapi/tabs/tabs.service.js +26 -26
  294. package/src/saas/openapi/users/user.model.js +10 -10
  295. package/src/saas/openapi/users/users.api.js +33 -33
  296. package/src/saas/openapi/users/users.service.js +51 -51
@@ -1,482 +1,482 @@
1
- const contractorsAPI = require('./contractors.api');
2
- const { RequestModel } = require('../../requests/models/edit.request.model');
3
- const { validateType } = require('../../../../common/validations/typeValidations');
4
- const { RecordModifyDateVerificationModel } = require('../models/verification.contractor.model');
5
- const { AssignRequirementModel } = require('../models/assign.requirement.model');
6
- const { ContractorDetailsModel } = require('../models/edit.contractor.model');
7
- const { LinkRequestModel } = require('../models/link.request.model');
8
- const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
9
- const { waitFor } = require('../../../../common/utils/timeUtils');
10
- const activationStatuses = require('../../../../common/consts/activationStatuses');
11
- const utils = require('../utils');
12
-
13
- const getContractorsByAccountId = async (accountId, context, activationStatus = null) => {
14
- if (activationStatus) {
15
- activationStatus = activationStatus.reduce((f, s) => `${f},${s}`);
16
- }
17
-
18
- return contractorsAPI.getContractorsByAccountId({ accountId, activationStatus }, context);
19
- };
20
-
21
- const getContractorById = (contractorId, context) => {
22
- return contractorsAPI.getContractorById(contractorId, context);
23
- };
24
-
25
- const getComplianceReportByRequestId = (requestId, context) => {
26
- return contractorsAPI.getComplianceReportByRequestId(requestId, context);
27
- };
28
-
29
- const getRecordHistory = (contractorId, context) => {
30
- return contractorsAPI.getRecordHistory(contractorId, context);
31
- };
32
-
33
- const getRecordHistoryEventReport = async (recordHistoryId, context, { expectError } = {}) => {
34
- const historyEventReportResponse = await contractorsAPI.getRecordHistoryEventReport(recordHistoryId, context);
35
-
36
- if (expectError) {
37
- return historyEventReportResponse;
38
- } else if (historyEventReportResponse.status !== httpResponseStatusCodes.OK) {
39
- throw new Error(`Failed to get record history event report: ${historyEventReportResponse.statusText}`);
40
- }
41
-
42
- return historyEventReportResponse.data;
43
- };
44
-
45
- const getRecordHistoryOverrideEventGapData = async (recordHistoryId, context, { expectError } = {}) => {
46
- const gapDataResponse = await contractorsAPI.getRecordHistoryOverrideEventGapData(recordHistoryId, context);
47
-
48
- if (expectError) {
49
- return gapDataResponse;
50
- } else if (gapDataResponse.status !== httpResponseStatusCodes.OK) {
51
- throw new Error(`Failed to get record history event gap data: ${gapDataResponse.statusText}`);
52
- }
53
-
54
- return gapDataResponse.data;
55
- };
56
-
57
- const getRecordHistoryOverrideGapRequestReport = async (recordHistoryId, context) => {
58
- const reportResponse = await contractorsAPI.getRecordHistoryOverrideGapRequestReport(recordHistoryId, context);
59
- return reportResponse.data;
60
- };
61
-
62
- const getRecordHistoryRequirementsChange = async (recordHistoryId, context, { expectError } = {}) => {
63
- const requirementsChangeResponse = await contractorsAPI.getRecordHistoryRequirementsChange(recordHistoryId, context);
64
-
65
- if (expectError) {
66
- return requirementsChangeResponse;
67
- } else if (requirementsChangeResponse.status !== httpResponseStatusCodes.OK) {
68
- throw new Error(`Failed to get record history requirements change: ${requirementsChangeResponse.statusText}`);
69
- }
70
-
71
- return requirementsChangeResponse.data;
72
- };
73
-
74
- const getComplianceReport = (encryptedData, context) => {
75
- return contractorsAPI.getComplianceReport(encryptedData, context);
76
- };
77
-
78
- const archiveRecord = (recordVerificationModel, context) => {
79
- validateType(recordVerificationModel, RecordModifyDateVerificationModel);
80
- return contractorsAPI.archiveRecord(recordVerificationModel, context);
81
- };
82
-
83
- const restoreRecord = (recordVerificationModel, context) => {
84
- validateType(recordVerificationModel, RecordModifyDateVerificationModel);
85
- return contractorsAPI.restoreRecord(recordVerificationModel, context);
86
- };
87
-
88
- const editContractor = (editRequestModel, context) => {
89
- validateType(editRequestModel, RequestModel);
90
- return contractorsAPI.editContractor(editRequestModel, context);
91
- };
92
-
93
- const updateExpiryDate = (contractorId, expiryDate, policyName) => {
94
- return contractorsAPI.updateExpiryDate(contractorId, expiryDate, policyName);
95
- };
96
-
97
- const assignRequirement = (requestId, assignRequirementModel, context) => {
98
- return contractorsAPI.assignRequirement(requestId, assignRequirementModel, context);
99
- };
100
-
101
- const updateInviteDate = (contractorId, inviteDate, context) => {
102
- return contractorsAPI.updateInviteDate(contractorId, inviteDate, context);
103
- };
104
-
105
- const updateLastInviteActionDate = (recordId, dateOffset, context) => {
106
- return contractorsAPI.updateLastInviteActionDate(recordId, dateOffset, context);
107
- };
108
-
109
- const searchInAutoComplete = ({ tabId, searchWord }, context) => {
110
- return contractorsAPI.searchInAutocomplete({ tabId, searchWord }, context);
111
- };
112
-
113
- const updateContractorUploadDate = (contractorId, uploadDate, context) => {
114
- validateType(uploadDate, Date);
115
- return contractorsAPI.updateContractorUploadDate(contractorId, uploadDate, context);
116
- };
117
-
118
- const changeRequirement = (recordModifyDateVerificationModel, context) => {
119
- validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
120
- return contractorsAPI.changeRequirement(recordModifyDateVerificationModel, context);
121
- };
122
-
123
- const sendGaps = (requestId, recordModifyDateVerificationModel, context) => {
124
- validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
125
- return contractorsAPI.sendGaps(requestId, recordModifyDateVerificationModel, context);
126
- };
127
-
128
- const requestNewCoiAboutToExpire = (requestId, recordModifyDateVerificationModel, context) => {
129
- validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
130
- return contractorsAPI.requestNewCoiAboutToExpire(requestId, recordModifyDateVerificationModel, context);
131
- };
132
-
133
- const requestNewCoiExpired = (requestId, recordModifyDateVerificationModel, context) => {
134
- validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
135
- return contractorsAPI.requestNewCoiExpired(requestId, recordModifyDateVerificationModel, context);
136
- };
137
-
138
- const resendInvitation = (requestId, recordModifyDateVerificationModel, context) => {
139
- validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
140
- return contractorsAPI.resendInvitation(requestId, recordModifyDateVerificationModel, context);
141
- };
142
-
143
- const muteNotifications = (recordModifyDateVerificationModel, context) => {
144
- validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
145
- return contractorsAPI.muteNotifications(recordModifyDateVerificationModel, context);
146
- };
147
-
148
- const muteNotificationsByRecordId = async (recordId, context) => {
149
- const recordModifyDateVerificationModel = await getRecordVerificationModel(recordId, context);
150
- const muteResponse = await contractorsAPI.muteNotifications(recordModifyDateVerificationModel, context);
151
-
152
- if (muteResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
153
- throw new Error(`Failed to mute record: ${muteResponse.statusText}`);
154
- }
155
-
156
- return muteResponse;
157
- };
158
-
159
- const unmuteNotifications = (recordModifyDateVerificationModel, context) => {
160
- validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
161
- return contractorsAPI.unmuteNotifications(recordModifyDateVerificationModel, context);
162
- };
163
-
164
- const buildBatchVerificationModels = (recordIds, context) => {
165
- return Promise.all(recordIds.map(recordId => getRecordVerificationModel(recordId, context)));
166
- };
167
-
168
- // The communication batches require a requestId per record. Build the base models from the record
169
- // ids via buildBatchVerificationModels, then attach each record's requestId.
170
- const buildCommunicationBatchVerificationModels = async (records, context) => {
171
- const models = await buildBatchVerificationModels(records.map(({ recordId }) => recordId), context);
172
- models.forEach((model, index) => {
173
- model.requestId = records[index].requestId;
174
- });
175
- return models;
176
- };
177
-
178
- const muteNotificationsBatch = async (recordIds, context, { expectError } = {}) => {
179
- const records = await buildBatchVerificationModels(recordIds, context);
180
- const response = await contractorsAPI.muteNotificationsBatch(records, context);
181
-
182
- if (expectError) {
183
- return response;
184
- }
185
-
186
- if (response.status !== httpResponseStatusCodes.OK) {
187
- throw Error(`Failed to batch mute records. Status code: ${response.status}`);
188
- }
189
-
190
- return response.data;
191
- };
192
-
193
- const unmuteNotificationsBatch = async (recordIds, context, { expectError } = {}) => {
194
- const records = await buildBatchVerificationModels(recordIds, context);
195
- const response = await contractorsAPI.unmuteNotificationsBatch(records, context);
196
-
197
- if (expectError) {
198
- return response;
199
- }
200
-
201
- if (response.status !== httpResponseStatusCodes.OK) {
202
- throw Error(`Failed to batch unmute records. Status code: ${response.status}`);
203
- }
204
-
205
- return response.data;
206
- };
207
-
208
- const archiveRecordsBatch = async (recordIds, context, { expectError } = {}) => {
209
- const records = await buildBatchVerificationModels(recordIds, context);
210
- const response = await contractorsAPI.archiveRecordsBatch(records, context);
211
-
212
- if (expectError) {
213
- return response;
214
- }
215
-
216
- if (response.status !== httpResponseStatusCodes.OK) {
217
- throw Error(`Failed to batch archive records. Status code: ${response.status}`);
218
- }
219
-
220
- return response.data;
221
- };
222
-
223
- const sendGapsBatch = async (records, context, { expectError } = {}) => {
224
- const models = await buildCommunicationBatchVerificationModels(records, context);
225
- const response = await contractorsAPI.sendGapsBatch(models, context);
226
-
227
- if (expectError) {
228
- return response;
229
- }
230
-
231
- if (response.status !== httpResponseStatusCodes.OK) {
232
- throw Error(`Failed to batch send gaps. Status code: ${response.status}`);
233
- }
234
-
235
- return response.data;
236
- };
237
-
238
- const requestNewCoiExpiredBatch = async (records, context, { expectError } = {}) => {
239
- const models = await buildCommunicationBatchVerificationModels(records, context);
240
- const response = await contractorsAPI.requestNewCoiExpiredBatch(models, context);
241
-
242
- if (expectError) {
243
- return response;
244
- }
245
-
246
- if (response.status !== httpResponseStatusCodes.OK) {
247
- throw Error(`Failed to batch request new COI (expired). Status code: ${response.status}`);
248
- }
249
-
250
- return response.data;
251
- };
252
-
253
- const requestNewCoiAboutToExpireBatch = async (records, context, { expectError } = {}) => {
254
- const models = await buildCommunicationBatchVerificationModels(records, context);
255
- const response = await contractorsAPI.requestNewCoiAboutToExpireBatch(models, context);
256
-
257
- if (expectError) {
258
- return response;
259
- }
260
-
261
- if (response.status !== httpResponseStatusCodes.OK) {
262
- throw Error(`Failed to batch request new COI (about to expire). Status code: ${response.status}`);
263
- }
264
-
265
- return response.data;
266
- };
267
-
268
- const resendInvitationsBatch = async (records, context, { expectError } = {}) => {
269
- const models = await buildCommunicationBatchVerificationModels(records, context);
270
- const response = await contractorsAPI.resendInvitationsBatch(models, context);
271
-
272
- if (expectError) {
273
- return response;
274
- }
275
-
276
- if (response.status !== httpResponseStatusCodes.OK) {
277
- throw Error(`Failed to batch resend invitations. Status code: ${response.status}`);
278
- }
279
-
280
- return response.data;
281
- };
282
-
283
- const unmuteNotificationsByRecordId = async (recordId, context) => {
284
- const recordModifyDateVerificationModel = await getRecordVerificationModel(recordId, context);
285
- const unmuteResponse = await contractorsAPI.unmuteNotifications(recordModifyDateVerificationModel, context);
286
-
287
- if (unmuteResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
288
- throw new Error(`Failed to unmute record: ${unmuteResponse.statusText}`);
289
- }
290
-
291
- return unmuteResponse;
292
- };
293
-
294
- const deleteByContractorId = async (contractorId, context, { expectError } = {}) => {
295
- const response = await contractorsAPI.deleteByContractorId(contractorId, context);
296
-
297
- if (response.status !== httpResponseStatusCodes.NO_CONTENT && !expectError) {
298
- throw new Error(`Failed to delete record: ${response.statusText}`);
299
- }
300
-
301
- return response;
302
- };
303
-
304
- const deleteAllRecordsInAccount = async (accountId, context, { activationStatus = [activationStatuses.ACTIVE, activationStatuses.ARCHIVED, activationStatuses.DRAFT] } = {}) => {
305
- const { data: existingRecords } = await getContractorsByAccountId(accountId, context, activationStatus);
306
-
307
- if (!existingRecords.length) {
308
- return;
309
- }
310
-
311
- const failed = [];
312
- for (const record of existingRecords) {
313
- try {
314
- await deleteByContractorId(record.id, context);
315
- } catch (firstError) {
316
- console.error(`Failed to delete record: ${record.company} (${firstError.message}), retrying...`);
317
- await waitFor(1).seconds;
318
- try {
319
- await deleteByContractorId(record.id, context);
320
- } catch (retryError) {
321
- console.error(`Failed to delete record: ${record.company} second time (${retryError.message}).`);
322
- failed.push(retryError.message);
323
- }
324
- }
325
- }
326
-
327
- if (failed.length) {
328
- throw Error(`Failed to delete ${failed.length} of ${existingRecords.length} records in account. ${failed[0]}`);
329
- }
330
- };
331
-
332
- const deleteAllActiveRecordsInAccount = async (accountId, context) => {
333
- return deleteAllRecordsInAccount(accountId, context, { activationStatus: [activationStatuses.ACTIVE] });
334
- };
335
-
336
- const getRecordVerificationModel = async (recordId, context, { requirementId, requirementDateModified } = {}) => {
337
- const { data: recordData } = await getContractorById(recordId, context);
338
- return new RecordModifyDateVerificationModel(recordData.id, { contractorDateModified: recordData.dateModified, requirementId, requirementDateModified });
339
- };
340
-
341
- const getRecordVerificationModelForDraftRecord = (request, { requirementId, requirementDateModified } = {}) => {
342
- const { record } = request;
343
- return new RecordModifyDateVerificationModel(record.id, { contractorDateModified: record.dateModified, requirementId, requirementDateModified });
344
- };
345
-
346
- const getAssignRequirementModel = (requirementId, companyName, emailAddress, { fileName, disableMail, existingCoiFileName } = {}) => {
347
- return new AssignRequirementModel(requirementId, companyName, emailAddress, { fileName, disableMail, existingCoiFileName });
348
- };
349
-
350
- const getLinkedProjectsCount = (recordId, context) => {
351
- return contractorsAPI.getLinkedProjectsCount(recordId, context);
352
- };
353
-
354
- const restoreByRecordId = async (recordId, context) => {
355
- const recordModifyModel = await getRecordVerificationModel(recordId, context);
356
- const restoreResponse = await restoreRecord(recordModifyModel, context);
357
-
358
- if (restoreResponse.status !== httpResponseStatusCodes.OK) {
359
- throw new Error(`Failed to restore record "${recordId}"\n${restoreResponse.statusText}`);
360
- }
361
-
362
- return restoreResponse;
363
- };
364
-
365
- const archiveByRecordId = async (recordId, context) => {
366
- const recordModifyModel = await getRecordVerificationModel(recordId, context);
367
- const archiveResponse = await archiveRecord(recordModifyModel, context);
368
-
369
- if (archiveResponse.status !== httpResponseStatusCodes.OK) {
370
- throw new Error(`Failed to archive record "${recordId}"\n${archiveResponse.statusText}`);
371
- }
372
-
373
- return archiveResponse;
374
- };
375
-
376
- const getInviteLinkStatus = (encryptedData, context) => {
377
- return contractorsAPI.getInviteLinkStatus(encryptedData, context);
378
- };
379
-
380
- const getContractorDetailsModel = recordConfig => {
381
- const apiDetailsConfig = utils.getRecordDetailsConfigInApiFormat(recordConfig);
382
- return new ContractorDetailsModel(apiDetailsConfig);
383
- };
384
-
385
- const getBasicDetailsById = async recordId => {
386
- const response = await contractorsAPI.getBasicDetailsById(recordId);
387
-
388
- if (response.status !== httpResponseStatusCodes.OK) {
389
- throw Error(`Failed to get basic record details by record id: ${recordId} - Response: ${response.status}`);
390
- }
391
-
392
- return response.data;
393
- };
394
-
395
- const getRecordsFromInsuredName = async (insuredName, accountIds) => {
396
- const response = await contractorsAPI.getRecordsFromInsuredName(insuredName, accountIds);
397
-
398
- if (response.status !== httpResponseStatusCodes.OK) {
399
- throw Error(`Failed to get records from insured name: ${insuredName} and accountIds: ${accountIds} - Response: ${response.status}`);
400
- }
401
-
402
- return response.data;
403
- };
404
-
405
- const linkDraftRequestToAccountRecord = async (requestToLink, targetAccountRecord, context, { shouldExpectError } = {}) => {
406
- const linkRequestModel = new LinkRequestModel(requestToLink, targetAccountRecord);
407
- const linkRequestResponse = await contractorsAPI.linkDraftRequestToAccountRecord(linkRequestModel, context);
408
-
409
- if (linkRequestResponse.status !== httpResponseStatusCodes.OK && !shouldExpectError) {
410
- throw Error(`Failed to link request - ${requestToLink.id} to accountRecord ${targetAccountRecord.id}\n${linkRequestResponse}`);
411
- } else {
412
- return linkRequestResponse;
413
- }
414
- };
415
-
416
- const changeRequirementsDirectly = async (recordId, newRequirementId, context) => {
417
- const recordVerificationModel = await getRecordVerificationModel(recordId, context);
418
- recordVerificationModel.requirementId = newRequirementId;
419
- const changeRequirementRes = await changeRequirement(recordVerificationModel, context);
420
-
421
- if (changeRequirementRes.status !== httpResponseStatusCodes.NO_CONTENT) {
422
- throw Error(`Failed to change requirement for record: ${recordId}`);
423
- }
424
- };
425
-
426
- const isRecordNotResponsive = async (recordId, context) => {
427
- const record = await getContractorById(recordId, context);
428
- return record.data.isNotResponsive;
429
- };
430
-
431
- module.exports = {
432
- changeRequirement,
433
- getContractorsByAccountId,
434
- getContractorById,
435
- getComplianceReportByRequestId,
436
- getRecordHistory,
437
- getRecordHistoryEventReport,
438
- getRecordHistoryOverrideEventGapData,
439
- getRecordHistoryOverrideGapRequestReport,
440
- getRecordHistoryRequirementsChange,
441
- getComplianceReport,
442
- archiveRecord,
443
- restoreRecord,
444
- editContractor,
445
- updateInviteDate,
446
- updateExpiryDate,
447
- searchInAutoComplete,
448
- updateContractorUploadDate,
449
- sendGaps,
450
- requestNewCoiAboutToExpire,
451
- requestNewCoiExpired,
452
- resendInvitation,
453
- muteNotifications,
454
- muteNotificationsByRecordId,
455
- unmuteNotifications,
456
- unmuteNotificationsByRecordId,
457
- muteNotificationsBatch,
458
- unmuteNotificationsBatch,
459
- archiveRecordsBatch,
460
- sendGapsBatch,
461
- requestNewCoiExpiredBatch,
462
- requestNewCoiAboutToExpireBatch,
463
- resendInvitationsBatch,
464
- deleteByContractorId,
465
- deleteAllRecordsInAccount,
466
- deleteAllActiveRecordsInAccount,
467
- getRecordVerificationModel,
468
- getRecordVerificationModelForDraftRecord,
469
- assignRequirement,
470
- getAssignRequirementModel,
471
- getLinkedProjectsCount,
472
- archiveByRecordId,
473
- restoreByRecordId,
474
- updateLastInviteActionDate,
475
- getInviteLinkStatus,
476
- getContractorDetailsModel,
477
- getBasicDetailsById,
478
- getRecordsFromInsuredName,
479
- linkDraftRequestToAccountRecord,
480
- changeRequirementsDirectly,
481
- isRecordNotResponsive
482
- };
1
+ const contractorsAPI = require('./contractors.api');
2
+ const { RequestModel } = require('../../requests/models/edit.request.model');
3
+ const { validateType } = require('../../../../common/validations/typeValidations');
4
+ const { RecordModifyDateVerificationModel } = require('../models/verification.contractor.model');
5
+ const { AssignRequirementModel } = require('../models/assign.requirement.model');
6
+ const { ContractorDetailsModel } = require('../models/edit.contractor.model');
7
+ const { LinkRequestModel } = require('../models/link.request.model');
8
+ const httpResponseStatusCodes = require('../../../../common/httpResponseStatusCodes.json');
9
+ const { waitFor } = require('../../../../common/utils/timeUtils');
10
+ const activationStatuses = require('../../../../common/consts/activationStatuses');
11
+ const utils = require('../utils');
12
+
13
+ const getContractorsByAccountId = async (accountId, context, activationStatus = null) => {
14
+ if (activationStatus) {
15
+ activationStatus = activationStatus.reduce((f, s) => `${f},${s}`);
16
+ }
17
+
18
+ return contractorsAPI.getContractorsByAccountId({ accountId, activationStatus }, context);
19
+ };
20
+
21
+ const getContractorById = (contractorId, context) => {
22
+ return contractorsAPI.getContractorById(contractorId, context);
23
+ };
24
+
25
+ const getComplianceReportByRequestId = (requestId, context) => {
26
+ return contractorsAPI.getComplianceReportByRequestId(requestId, context);
27
+ };
28
+
29
+ const getRecordHistory = (contractorId, context) => {
30
+ return contractorsAPI.getRecordHistory(contractorId, context);
31
+ };
32
+
33
+ const getRecordHistoryEventReport = async (recordHistoryId, context, { expectError } = {}) => {
34
+ const historyEventReportResponse = await contractorsAPI.getRecordHistoryEventReport(recordHistoryId, context);
35
+
36
+ if (expectError) {
37
+ return historyEventReportResponse;
38
+ } else if (historyEventReportResponse.status !== httpResponseStatusCodes.OK) {
39
+ throw new Error(`Failed to get record history event report: ${historyEventReportResponse.statusText}`);
40
+ }
41
+
42
+ return historyEventReportResponse.data;
43
+ };
44
+
45
+ const getRecordHistoryOverrideEventGapData = async (recordHistoryId, context, { expectError } = {}) => {
46
+ const gapDataResponse = await contractorsAPI.getRecordHistoryOverrideEventGapData(recordHistoryId, context);
47
+
48
+ if (expectError) {
49
+ return gapDataResponse;
50
+ } else if (gapDataResponse.status !== httpResponseStatusCodes.OK) {
51
+ throw new Error(`Failed to get record history event gap data: ${gapDataResponse.statusText}`);
52
+ }
53
+
54
+ return gapDataResponse.data;
55
+ };
56
+
57
+ const getRecordHistoryOverrideGapRequestReport = async (recordHistoryId, context) => {
58
+ const reportResponse = await contractorsAPI.getRecordHistoryOverrideGapRequestReport(recordHistoryId, context);
59
+ return reportResponse.data;
60
+ };
61
+
62
+ const getRecordHistoryRequirementsChange = async (recordHistoryId, context, { expectError } = {}) => {
63
+ const requirementsChangeResponse = await contractorsAPI.getRecordHistoryRequirementsChange(recordHistoryId, context);
64
+
65
+ if (expectError) {
66
+ return requirementsChangeResponse;
67
+ } else if (requirementsChangeResponse.status !== httpResponseStatusCodes.OK) {
68
+ throw new Error(`Failed to get record history requirements change: ${requirementsChangeResponse.statusText}`);
69
+ }
70
+
71
+ return requirementsChangeResponse.data;
72
+ };
73
+
74
+ const getComplianceReport = (encryptedData, context) => {
75
+ return contractorsAPI.getComplianceReport(encryptedData, context);
76
+ };
77
+
78
+ const archiveRecord = (recordVerificationModel, context) => {
79
+ validateType(recordVerificationModel, RecordModifyDateVerificationModel);
80
+ return contractorsAPI.archiveRecord(recordVerificationModel, context);
81
+ };
82
+
83
+ const restoreRecord = (recordVerificationModel, context) => {
84
+ validateType(recordVerificationModel, RecordModifyDateVerificationModel);
85
+ return contractorsAPI.restoreRecord(recordVerificationModel, context);
86
+ };
87
+
88
+ const editContractor = (editRequestModel, context) => {
89
+ validateType(editRequestModel, RequestModel);
90
+ return contractorsAPI.editContractor(editRequestModel, context);
91
+ };
92
+
93
+ const updateExpiryDate = (contractorId, expiryDate, policyName) => {
94
+ return contractorsAPI.updateExpiryDate(contractorId, expiryDate, policyName);
95
+ };
96
+
97
+ const assignRequirement = (requestId, assignRequirementModel, context) => {
98
+ return contractorsAPI.assignRequirement(requestId, assignRequirementModel, context);
99
+ };
100
+
101
+ const updateInviteDate = (contractorId, inviteDate, context) => {
102
+ return contractorsAPI.updateInviteDate(contractorId, inviteDate, context);
103
+ };
104
+
105
+ const updateLastInviteActionDate = (recordId, dateOffset, context) => {
106
+ return contractorsAPI.updateLastInviteActionDate(recordId, dateOffset, context);
107
+ };
108
+
109
+ const searchInAutoComplete = ({ tabId, searchWord }, context) => {
110
+ return contractorsAPI.searchInAutocomplete({ tabId, searchWord }, context);
111
+ };
112
+
113
+ const updateContractorUploadDate = (contractorId, uploadDate, context) => {
114
+ validateType(uploadDate, Date);
115
+ return contractorsAPI.updateContractorUploadDate(contractorId, uploadDate, context);
116
+ };
117
+
118
+ const changeRequirement = (recordModifyDateVerificationModel, context) => {
119
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
120
+ return contractorsAPI.changeRequirement(recordModifyDateVerificationModel, context);
121
+ };
122
+
123
+ const sendGaps = (requestId, recordModifyDateVerificationModel, context) => {
124
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
125
+ return contractorsAPI.sendGaps(requestId, recordModifyDateVerificationModel, context);
126
+ };
127
+
128
+ const requestNewCoiAboutToExpire = (requestId, recordModifyDateVerificationModel, context) => {
129
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
130
+ return contractorsAPI.requestNewCoiAboutToExpire(requestId, recordModifyDateVerificationModel, context);
131
+ };
132
+
133
+ const requestNewCoiExpired = (requestId, recordModifyDateVerificationModel, context) => {
134
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
135
+ return contractorsAPI.requestNewCoiExpired(requestId, recordModifyDateVerificationModel, context);
136
+ };
137
+
138
+ const resendInvitation = (requestId, recordModifyDateVerificationModel, context) => {
139
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
140
+ return contractorsAPI.resendInvitation(requestId, recordModifyDateVerificationModel, context);
141
+ };
142
+
143
+ const muteNotifications = (recordModifyDateVerificationModel, context) => {
144
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
145
+ return contractorsAPI.muteNotifications(recordModifyDateVerificationModel, context);
146
+ };
147
+
148
+ const muteNotificationsByRecordId = async (recordId, context) => {
149
+ const recordModifyDateVerificationModel = await getRecordVerificationModel(recordId, context);
150
+ const muteResponse = await contractorsAPI.muteNotifications(recordModifyDateVerificationModel, context);
151
+
152
+ if (muteResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
153
+ throw new Error(`Failed to mute record: ${muteResponse.statusText}`);
154
+ }
155
+
156
+ return muteResponse;
157
+ };
158
+
159
+ const unmuteNotifications = (recordModifyDateVerificationModel, context) => {
160
+ validateType(recordModifyDateVerificationModel, RecordModifyDateVerificationModel);
161
+ return contractorsAPI.unmuteNotifications(recordModifyDateVerificationModel, context);
162
+ };
163
+
164
+ const buildBatchVerificationModels = (recordIds, context) => {
165
+ return Promise.all(recordIds.map(recordId => getRecordVerificationModel(recordId, context)));
166
+ };
167
+
168
+ // The communication batches require a requestId per record. Build the base models from the record
169
+ // ids via buildBatchVerificationModels, then attach each record's requestId.
170
+ const buildCommunicationBatchVerificationModels = async (records, context) => {
171
+ const models = await buildBatchVerificationModels(records.map(({ recordId }) => recordId), context);
172
+ models.forEach((model, index) => {
173
+ model.requestId = records[index].requestId;
174
+ });
175
+ return models;
176
+ };
177
+
178
+ const muteNotificationsBatch = async (recordIds, context, { expectError } = {}) => {
179
+ const records = await buildBatchVerificationModels(recordIds, context);
180
+ const response = await contractorsAPI.muteNotificationsBatch(records, context);
181
+
182
+ if (expectError) {
183
+ return response;
184
+ }
185
+
186
+ if (response.status !== httpResponseStatusCodes.OK) {
187
+ throw Error(`Failed to batch mute records. Status code: ${response.status}`);
188
+ }
189
+
190
+ return response.data;
191
+ };
192
+
193
+ const unmuteNotificationsBatch = async (recordIds, context, { expectError } = {}) => {
194
+ const records = await buildBatchVerificationModels(recordIds, context);
195
+ const response = await contractorsAPI.unmuteNotificationsBatch(records, context);
196
+
197
+ if (expectError) {
198
+ return response;
199
+ }
200
+
201
+ if (response.status !== httpResponseStatusCodes.OK) {
202
+ throw Error(`Failed to batch unmute records. Status code: ${response.status}`);
203
+ }
204
+
205
+ return response.data;
206
+ };
207
+
208
+ const archiveRecordsBatch = async (recordIds, context, { expectError } = {}) => {
209
+ const records = await buildBatchVerificationModels(recordIds, context);
210
+ const response = await contractorsAPI.archiveRecordsBatch(records, context);
211
+
212
+ if (expectError) {
213
+ return response;
214
+ }
215
+
216
+ if (response.status !== httpResponseStatusCodes.OK) {
217
+ throw Error(`Failed to batch archive records. Status code: ${response.status}`);
218
+ }
219
+
220
+ return response.data;
221
+ };
222
+
223
+ const sendGapsBatch = async (records, context, { expectError } = {}) => {
224
+ const models = await buildCommunicationBatchVerificationModels(records, context);
225
+ const response = await contractorsAPI.sendGapsBatch(models, context);
226
+
227
+ if (expectError) {
228
+ return response;
229
+ }
230
+
231
+ if (response.status !== httpResponseStatusCodes.OK) {
232
+ throw Error(`Failed to batch send gaps. Status code: ${response.status}`);
233
+ }
234
+
235
+ return response.data;
236
+ };
237
+
238
+ const requestNewCoiExpiredBatch = async (records, context, { expectError } = {}) => {
239
+ const models = await buildCommunicationBatchVerificationModels(records, context);
240
+ const response = await contractorsAPI.requestNewCoiExpiredBatch(models, context);
241
+
242
+ if (expectError) {
243
+ return response;
244
+ }
245
+
246
+ if (response.status !== httpResponseStatusCodes.OK) {
247
+ throw Error(`Failed to batch request new COI (expired). Status code: ${response.status}`);
248
+ }
249
+
250
+ return response.data;
251
+ };
252
+
253
+ const requestNewCoiAboutToExpireBatch = async (records, context, { expectError } = {}) => {
254
+ const models = await buildCommunicationBatchVerificationModels(records, context);
255
+ const response = await contractorsAPI.requestNewCoiAboutToExpireBatch(models, context);
256
+
257
+ if (expectError) {
258
+ return response;
259
+ }
260
+
261
+ if (response.status !== httpResponseStatusCodes.OK) {
262
+ throw Error(`Failed to batch request new COI (about to expire). Status code: ${response.status}`);
263
+ }
264
+
265
+ return response.data;
266
+ };
267
+
268
+ const resendInvitationsBatch = async (records, context, { expectError } = {}) => {
269
+ const models = await buildCommunicationBatchVerificationModels(records, context);
270
+ const response = await contractorsAPI.resendInvitationsBatch(models, context);
271
+
272
+ if (expectError) {
273
+ return response;
274
+ }
275
+
276
+ if (response.status !== httpResponseStatusCodes.OK) {
277
+ throw Error(`Failed to batch resend invitations. Status code: ${response.status}`);
278
+ }
279
+
280
+ return response.data;
281
+ };
282
+
283
+ const unmuteNotificationsByRecordId = async (recordId, context) => {
284
+ const recordModifyDateVerificationModel = await getRecordVerificationModel(recordId, context);
285
+ const unmuteResponse = await contractorsAPI.unmuteNotifications(recordModifyDateVerificationModel, context);
286
+
287
+ if (unmuteResponse.status !== httpResponseStatusCodes.NO_CONTENT) {
288
+ throw new Error(`Failed to unmute record: ${unmuteResponse.statusText}`);
289
+ }
290
+
291
+ return unmuteResponse;
292
+ };
293
+
294
+ const deleteByContractorId = async (contractorId, context, { expectError } = {}) => {
295
+ const response = await contractorsAPI.deleteByContractorId(contractorId, context);
296
+
297
+ if (response.status !== httpResponseStatusCodes.NO_CONTENT && !expectError) {
298
+ throw new Error(`Failed to delete record: ${response.statusText}`);
299
+ }
300
+
301
+ return response;
302
+ };
303
+
304
+ const deleteAllRecordsInAccount = async (accountId, context, { activationStatus = [activationStatuses.ACTIVE, activationStatuses.ARCHIVED, activationStatuses.DRAFT] } = {}) => {
305
+ const { data: existingRecords } = await getContractorsByAccountId(accountId, context, activationStatus);
306
+
307
+ if (!existingRecords.length) {
308
+ return;
309
+ }
310
+
311
+ const failed = [];
312
+ for (const record of existingRecords) {
313
+ try {
314
+ await deleteByContractorId(record.id, context);
315
+ } catch (firstError) {
316
+ console.error(`Failed to delete record: ${record.company} (${firstError.message}), retrying...`);
317
+ await waitFor(1).seconds;
318
+ try {
319
+ await deleteByContractorId(record.id, context);
320
+ } catch (retryError) {
321
+ console.error(`Failed to delete record: ${record.company} second time (${retryError.message}).`);
322
+ failed.push(retryError.message);
323
+ }
324
+ }
325
+ }
326
+
327
+ if (failed.length) {
328
+ throw Error(`Failed to delete ${failed.length} of ${existingRecords.length} records in account. ${failed[0]}`);
329
+ }
330
+ };
331
+
332
+ const deleteAllActiveRecordsInAccount = async (accountId, context) => {
333
+ return deleteAllRecordsInAccount(accountId, context, { activationStatus: [activationStatuses.ACTIVE] });
334
+ };
335
+
336
+ const getRecordVerificationModel = async (recordId, context, { requirementId, requirementDateModified } = {}) => {
337
+ const { data: recordData } = await getContractorById(recordId, context);
338
+ return new RecordModifyDateVerificationModel(recordData.id, { contractorDateModified: recordData.dateModified, requirementId, requirementDateModified });
339
+ };
340
+
341
+ const getRecordVerificationModelForDraftRecord = (request, { requirementId, requirementDateModified } = {}) => {
342
+ const { record } = request;
343
+ return new RecordModifyDateVerificationModel(record.id, { contractorDateModified: record.dateModified, requirementId, requirementDateModified });
344
+ };
345
+
346
+ const getAssignRequirementModel = (requirementId, companyName, emailAddress, { fileName, disableMail, existingCoiFileName } = {}) => {
347
+ return new AssignRequirementModel(requirementId, companyName, emailAddress, { fileName, disableMail, existingCoiFileName });
348
+ };
349
+
350
+ const getLinkedProjectsCount = (recordId, context) => {
351
+ return contractorsAPI.getLinkedProjectsCount(recordId, context);
352
+ };
353
+
354
+ const restoreByRecordId = async (recordId, context) => {
355
+ const recordModifyModel = await getRecordVerificationModel(recordId, context);
356
+ const restoreResponse = await restoreRecord(recordModifyModel, context);
357
+
358
+ if (restoreResponse.status !== httpResponseStatusCodes.OK) {
359
+ throw new Error(`Failed to restore record "${recordId}"\n${restoreResponse.statusText}`);
360
+ }
361
+
362
+ return restoreResponse;
363
+ };
364
+
365
+ const archiveByRecordId = async (recordId, context) => {
366
+ const recordModifyModel = await getRecordVerificationModel(recordId, context);
367
+ const archiveResponse = await archiveRecord(recordModifyModel, context);
368
+
369
+ if (archiveResponse.status !== httpResponseStatusCodes.OK) {
370
+ throw new Error(`Failed to archive record "${recordId}"\n${archiveResponse.statusText}`);
371
+ }
372
+
373
+ return archiveResponse;
374
+ };
375
+
376
+ const getInviteLinkStatus = (encryptedData, context) => {
377
+ return contractorsAPI.getInviteLinkStatus(encryptedData, context);
378
+ };
379
+
380
+ const getContractorDetailsModel = recordConfig => {
381
+ const apiDetailsConfig = utils.getRecordDetailsConfigInApiFormat(recordConfig);
382
+ return new ContractorDetailsModel(apiDetailsConfig);
383
+ };
384
+
385
+ const getBasicDetailsById = async recordId => {
386
+ const response = await contractorsAPI.getBasicDetailsById(recordId);
387
+
388
+ if (response.status !== httpResponseStatusCodes.OK) {
389
+ throw Error(`Failed to get basic record details by record id: ${recordId} - Response: ${response.status}`);
390
+ }
391
+
392
+ return response.data;
393
+ };
394
+
395
+ const getRecordsFromInsuredName = async (insuredName, accountIds) => {
396
+ const response = await contractorsAPI.getRecordsFromInsuredName(insuredName, accountIds);
397
+
398
+ if (response.status !== httpResponseStatusCodes.OK) {
399
+ throw Error(`Failed to get records from insured name: ${insuredName} and accountIds: ${accountIds} - Response: ${response.status}`);
400
+ }
401
+
402
+ return response.data;
403
+ };
404
+
405
+ const linkDraftRequestToAccountRecord = async (requestToLink, targetAccountRecord, context, { shouldExpectError } = {}) => {
406
+ const linkRequestModel = new LinkRequestModel(requestToLink, targetAccountRecord);
407
+ const linkRequestResponse = await contractorsAPI.linkDraftRequestToAccountRecord(linkRequestModel, context);
408
+
409
+ if (linkRequestResponse.status !== httpResponseStatusCodes.OK && !shouldExpectError) {
410
+ throw Error(`Failed to link request - ${requestToLink.id} to accountRecord ${targetAccountRecord.id}\n${linkRequestResponse}`);
411
+ } else {
412
+ return linkRequestResponse;
413
+ }
414
+ };
415
+
416
+ const changeRequirementsDirectly = async (recordId, newRequirementId, context) => {
417
+ const recordVerificationModel = await getRecordVerificationModel(recordId, context);
418
+ recordVerificationModel.requirementId = newRequirementId;
419
+ const changeRequirementRes = await changeRequirement(recordVerificationModel, context);
420
+
421
+ if (changeRequirementRes.status !== httpResponseStatusCodes.NO_CONTENT) {
422
+ throw Error(`Failed to change requirement for record: ${recordId}`);
423
+ }
424
+ };
425
+
426
+ const isRecordNotResponsive = async (recordId, context) => {
427
+ const record = await getContractorById(recordId, context);
428
+ return record.data.isNotResponsive;
429
+ };
430
+
431
+ module.exports = {
432
+ changeRequirement,
433
+ getContractorsByAccountId,
434
+ getContractorById,
435
+ getComplianceReportByRequestId,
436
+ getRecordHistory,
437
+ getRecordHistoryEventReport,
438
+ getRecordHistoryOverrideEventGapData,
439
+ getRecordHistoryOverrideGapRequestReport,
440
+ getRecordHistoryRequirementsChange,
441
+ getComplianceReport,
442
+ archiveRecord,
443
+ restoreRecord,
444
+ editContractor,
445
+ updateInviteDate,
446
+ updateExpiryDate,
447
+ searchInAutoComplete,
448
+ updateContractorUploadDate,
449
+ sendGaps,
450
+ requestNewCoiAboutToExpire,
451
+ requestNewCoiExpired,
452
+ resendInvitation,
453
+ muteNotifications,
454
+ muteNotificationsByRecordId,
455
+ unmuteNotifications,
456
+ unmuteNotificationsByRecordId,
457
+ muteNotificationsBatch,
458
+ unmuteNotificationsBatch,
459
+ archiveRecordsBatch,
460
+ sendGapsBatch,
461
+ requestNewCoiExpiredBatch,
462
+ requestNewCoiAboutToExpireBatch,
463
+ resendInvitationsBatch,
464
+ deleteByContractorId,
465
+ deleteAllRecordsInAccount,
466
+ deleteAllActiveRecordsInAccount,
467
+ getRecordVerificationModel,
468
+ getRecordVerificationModelForDraftRecord,
469
+ assignRequirement,
470
+ getAssignRequirementModel,
471
+ getLinkedProjectsCount,
472
+ archiveByRecordId,
473
+ restoreByRecordId,
474
+ updateLastInviteActionDate,
475
+ getInviteLinkStatus,
476
+ getContractorDetailsModel,
477
+ getBasicDetailsById,
478
+ getRecordsFromInsuredName,
479
+ linkDraftRequestToAccountRecord,
480
+ changeRequirementsDirectly,
481
+ isRecordNotResponsive
482
+ };