@ironcode/vas-lib 1.15.0 → 1.16.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (158) hide show
  1. package/cjs/lib/control-value/vas-camera-control-value.model.js +1 -2
  2. package/cjs/lib/control-value/vas-camera-control-value.model.js.map +1 -1
  3. package/cjs/lib/controls-config/vas-control-config-direction.enum.js +1 -1
  4. package/cjs/lib/controls-config/vas-control-config-direction.enum.js.map +1 -1
  5. package/cjs/lib/entity/index.d.ts +1 -1
  6. package/cjs/lib/entity/index.d.ts.map +1 -1
  7. package/cjs/lib/entity/index.js +1 -1
  8. package/cjs/lib/entity/index.js.map +1 -1
  9. package/cjs/lib/entity/vas-account.dto.d.ts +1 -1
  10. package/cjs/lib/entity/vas-account.dto.d.ts.map +1 -1
  11. package/cjs/lib/entity/vas-account.dto.js +1 -1
  12. package/cjs/lib/entity/vas-account.dto.js.map +1 -1
  13. package/cjs/lib/entity/vas-control.model.js.map +1 -1
  14. package/cjs/lib/entity/vas-field.model.js.map +1 -1
  15. package/cjs/lib/entity/vas-file.dto.js +1 -2
  16. package/cjs/lib/entity/vas-file.dto.js.map +1 -1
  17. package/cjs/lib/entity/vas-file.model.js.map +1 -1
  18. package/cjs/lib/entity/vas-fire-user.model.d.ts +1 -1
  19. package/cjs/lib/entity/vas-fire-user.model.d.ts.map +1 -1
  20. package/cjs/lib/entity/vas-fire-user.model.js.map +1 -1
  21. package/cjs/lib/entity/vas-form-config.model.d.ts +3 -13
  22. package/cjs/lib/entity/vas-form-config.model.d.ts.map +1 -1
  23. package/cjs/lib/entity/vas-form-config.model.js.map +1 -1
  24. package/cjs/lib/entity/vas-form.model.js.map +1 -1
  25. package/cjs/lib/entity/vas-group.model.js.map +1 -1
  26. package/cjs/lib/entity/vas-invitation.d.ts +1 -1
  27. package/cjs/lib/entity/vas-invitation.d.ts.map +1 -1
  28. package/cjs/lib/entity/vas-invitation.js +1 -1
  29. package/cjs/lib/entity/vas-invitation.js.map +1 -1
  30. package/cjs/lib/entity/vas-job-action.dto.d.ts +22 -7
  31. package/cjs/lib/entity/vas-job-action.dto.d.ts.map +1 -1
  32. package/cjs/lib/entity/vas-job-action.dto.js +10 -1
  33. package/cjs/lib/entity/vas-job-action.dto.js.map +1 -1
  34. package/cjs/lib/entity/vas-job-status.d.ts +28 -0
  35. package/cjs/lib/entity/vas-job-status.d.ts.map +1 -0
  36. package/cjs/lib/entity/vas-job-status.js +46 -0
  37. package/cjs/lib/entity/vas-job-status.js.map +1 -0
  38. package/cjs/lib/entity/vas-job.model.js.map +1 -1
  39. package/cjs/lib/entity/vas-user.model.d.ts +1 -1
  40. package/cjs/lib/entity/vas-user.model.d.ts.map +1 -1
  41. package/cjs/lib/utils/find-form-control.js.map +1 -1
  42. package/cjs/lib/utils/get-value-by-path.d.ts.map +1 -1
  43. package/cjs/lib/utils/get-value-by-path.js.map +1 -1
  44. package/cjs/lib/utils/is-array-string.d.ts +1 -1
  45. package/cjs/lib/utils/is-array-string.d.ts.map +1 -1
  46. package/cjs/lib/utils/omit.d.ts.map +1 -1
  47. package/cjs/lib/utils/omit.js.map +1 -1
  48. package/cjs/lib/utils/only.d.ts.map +1 -1
  49. package/cjs/lib/utils/only.js.map +1 -1
  50. package/{fesm2020 → fesm2022}/ironcode-vas-lib.mjs +570 -2
  51. package/fesm2022/ironcode-vas-lib.mjs.map +1 -0
  52. package/lib/entity/index.d.ts +1 -1
  53. package/lib/entity/vas-account.dto.d.ts +1 -1
  54. package/lib/entity/vas-fire-user.model.d.ts +1 -1
  55. package/lib/entity/vas-form-config.model.d.ts +3 -13
  56. package/lib/entity/vas-invitation.d.ts +1 -1
  57. package/lib/entity/vas-job-action.dto.d.ts +22 -7
  58. package/lib/entity/vas-job-status.d.ts +27 -0
  59. package/lib/entity/vas-user.model.d.ts +1 -1
  60. package/lib/utils/is-array-string.d.ts +1 -1
  61. package/package.json +3 -11
  62. package/cjs/lib/entity/vas-job-status.dto.d.ts +0 -8
  63. package/cjs/lib/entity/vas-job-status.dto.d.ts.map +0 -1
  64. package/cjs/lib/entity/vas-job-status.dto.js +0 -3
  65. package/cjs/lib/entity/vas-job-status.dto.js.map +0 -1
  66. package/cjs/package.json +0 -5
  67. package/esm2020/ironcode-vas-lib.mjs +0 -5
  68. package/esm2020/lib/control-value/index.mjs +0 -3
  69. package/esm2020/lib/control-value/vas-camera-control-value.model.mjs +0 -8
  70. package/esm2020/lib/control-value/vas-function-control-value.dto.mjs +0 -2
  71. package/esm2020/lib/controls-config/index.mjs +0 -5
  72. package/esm2020/lib/controls-config/vas-control-config-direction.enum.mjs +0 -8
  73. package/esm2020/lib/controls-config/vas-control-config.model.mjs +0 -2
  74. package/esm2020/lib/controls-config/vas-function-control-config.dto.mjs +0 -2
  75. package/esm2020/lib/controls-config/vas-select-control-config.model.mjs +0 -2
  76. package/esm2020/lib/elastic/index.mjs +0 -2
  77. package/esm2020/lib/elastic/job.elastic-doc.mjs +0 -2
  78. package/esm2020/lib/entity/index.mjs +0 -70
  79. package/esm2020/lib/entity/vas-access-group.dto.mjs +0 -2
  80. package/esm2020/lib/entity/vas-account-config.dto.mjs +0 -2
  81. package/esm2020/lib/entity/vas-account-object.dto.mjs +0 -2
  82. package/esm2020/lib/entity/vas-account-object.model.mjs +0 -24
  83. package/esm2020/lib/entity/vas-account.dto.mjs +0 -7
  84. package/esm2020/lib/entity/vas-base.dto.mjs +0 -2
  85. package/esm2020/lib/entity/vas-base.model.mjs +0 -34
  86. package/esm2020/lib/entity/vas-branch.dto.mjs +0 -2
  87. package/esm2020/lib/entity/vas-branch.model.mjs +0 -68
  88. package/esm2020/lib/entity/vas-contact-type.dto.mjs +0 -2
  89. package/esm2020/lib/entity/vas-contact.dto.mjs +0 -2
  90. package/esm2020/lib/entity/vas-contact.model.mjs +0 -101
  91. package/esm2020/lib/entity/vas-control-type.dto.mjs +0 -2
  92. package/esm2020/lib/entity/vas-control-type.model.mjs +0 -52
  93. package/esm2020/lib/entity/vas-control.dto.mjs +0 -2
  94. package/esm2020/lib/entity/vas-control.model.mjs +0 -191
  95. package/esm2020/lib/entity/vas-field.dto.mjs +0 -2
  96. package/esm2020/lib/entity/vas-field.model.mjs +0 -112
  97. package/esm2020/lib/entity/vas-file.dto.mjs +0 -9
  98. package/esm2020/lib/entity/vas-file.model.mjs +0 -135
  99. package/esm2020/lib/entity/vas-fire-user.dto.mjs +0 -2
  100. package/esm2020/lib/entity/vas-fire-user.model.mjs +0 -102
  101. package/esm2020/lib/entity/vas-form-config.dto.mjs +0 -2
  102. package/esm2020/lib/entity/vas-form-config.model.mjs +0 -31
  103. package/esm2020/lib/entity/vas-form.dto.mjs +0 -2
  104. package/esm2020/lib/entity/vas-form.model.mjs +0 -215
  105. package/esm2020/lib/entity/vas-group.dto.mjs +0 -2
  106. package/esm2020/lib/entity/vas-group.model.mjs +0 -108
  107. package/esm2020/lib/entity/vas-instruction-job-field.dto.mjs +0 -2
  108. package/esm2020/lib/entity/vas-instruction-job-field.model.mjs +0 -48
  109. package/esm2020/lib/entity/vas-instruction-job.dto.mjs +0 -2
  110. package/esm2020/lib/entity/vas-instruction-job.model.mjs +0 -81
  111. package/esm2020/lib/entity/vas-instruction-provider.dto.mjs +0 -2
  112. package/esm2020/lib/entity/vas-instruction-provider.model.mjs +0 -66
  113. package/esm2020/lib/entity/vas-instruction.dto.mjs +0 -2
  114. package/esm2020/lib/entity/vas-instruction.model.mjs +0 -52
  115. package/esm2020/lib/entity/vas-invitation.mjs +0 -88
  116. package/esm2020/lib/entity/vas-job-action.dto.mjs +0 -22
  117. package/esm2020/lib/entity/vas-job-copy.mjs +0 -39
  118. package/esm2020/lib/entity/vas-job-data.dto.mjs +0 -2
  119. package/esm2020/lib/entity/vas-job-data.model.mjs +0 -21
  120. package/esm2020/lib/entity/vas-job-email.dto.mjs +0 -2
  121. package/esm2020/lib/entity/vas-job-email.model.mjs +0 -85
  122. package/esm2020/lib/entity/vas-job-status.dto.mjs +0 -2
  123. package/esm2020/lib/entity/vas-job-type.dto.mjs +0 -2
  124. package/esm2020/lib/entity/vas-job.dto.mjs +0 -2
  125. package/esm2020/lib/entity/vas-job.model.mjs +0 -529
  126. package/esm2020/lib/entity/vas-lookup-type.dto.mjs +0 -2
  127. package/esm2020/lib/entity/vas-lookup.dto.mjs +0 -2
  128. package/esm2020/lib/entity/vas-lookup.model.mjs +0 -75
  129. package/esm2020/lib/entity/vas-membership.dto.mjs +0 -2
  130. package/esm2020/lib/entity/vas-membership.model.mjs +0 -62
  131. package/esm2020/lib/entity/vas-note.dto.mjs +0 -2
  132. package/esm2020/lib/entity/vas-note.model.mjs +0 -68
  133. package/esm2020/lib/entity/vas-report-layout.dto.mjs +0 -2
  134. package/esm2020/lib/entity/vas-report-layout.model.mjs +0 -22
  135. package/esm2020/lib/entity/vas-report-request.dto.mjs +0 -2
  136. package/esm2020/lib/entity/vas-report-request.model.mjs +0 -44
  137. package/esm2020/lib/entity/vas-report.dto.mjs +0 -2
  138. package/esm2020/lib/entity/vas-report.model.mjs +0 -72
  139. package/esm2020/lib/entity/vas-restricted-account-object.dto.mjs +0 -2
  140. package/esm2020/lib/entity/vas-restricted-account-object.model.mjs +0 -24
  141. package/esm2020/lib/entity/vas-task-type.dto.mjs +0 -2
  142. package/esm2020/lib/entity/vas-task.dto.mjs +0 -2
  143. package/esm2020/lib/entity/vas-task.model.mjs +0 -80
  144. package/esm2020/lib/entity/vas-user.dto.mjs +0 -2
  145. package/esm2020/lib/entity/vas-user.model.mjs +0 -42
  146. package/esm2020/lib/entity/vas-vehicle.dto.mjs +0 -2
  147. package/esm2020/lib/entity/vas-vehicle.model.mjs +0 -69
  148. package/esm2020/lib/model/geo-location.mjs +0 -12
  149. package/esm2020/lib/model/index.mjs +0 -3
  150. package/esm2020/lib/model/vas-time-range.model.mjs +0 -2
  151. package/esm2020/lib/utils/get-value-by-path.mjs +0 -64
  152. package/esm2020/lib/utils/is-array-string.mjs +0 -4
  153. package/esm2020/lib/utils/only.mjs +0 -22
  154. package/esm2020/public-api.mjs +0 -6
  155. package/fesm2015/ironcode-vas-lib.mjs +0 -2736
  156. package/fesm2015/ironcode-vas-lib.mjs.map +0 -1
  157. package/fesm2020/ironcode-vas-lib.mjs.map +0 -1
  158. package/lib/entity/vas-job-status.dto.d.ts +0 -7
@@ -1,2736 +0,0 @@
1
- import { UUID } from 'angular2-uuid';
2
- import moment from 'moment';
3
-
4
- function isCameraControlValueV1(object) {
5
- return object instanceof Object
6
- && 'webPath' in object
7
- && 'path' in object
8
- && 'url' in object
9
- && 'id' in object;
10
- }
11
-
12
- var VasControlConfigDirection;
13
- (function (VasControlConfigDirection) {
14
- // eslint-disable-next-line @typescript-eslint/naming-convention
15
- VasControlConfigDirection[VasControlConfigDirection["ROW"] = 0] = "ROW";
16
- // eslint-disable-next-line @typescript-eslint/naming-convention
17
- VasControlConfigDirection[VasControlConfigDirection["COLUMN"] = 1] = "COLUMN";
18
- })(VasControlConfigDirection || (VasControlConfigDirection = {}));
19
-
20
- /**
21
- * BaseEntityModel
22
- */
23
- class VasBaseModel {
24
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName) {
25
- this.id = id;
26
- this.created = created;
27
- this.serverCreated = serverCreated;
28
- this.createdBy = createdBy;
29
- this.modified = modified;
30
- this.serverModified = serverModified;
31
- this.modifiedBy = modifiedBy;
32
- this.createdByName = createdByName;
33
- this.modifiedByName = modifiedByName;
34
- }
35
- static fromDto(dto) {
36
- return new VasBaseModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '');
37
- }
38
- static create(user, values = {}) {
39
- return this.fromDto(Object.assign({ id: UUID.UUID(), created: moment().toISOString(), modified: moment().toISOString(), createdBy: (user === null || user === void 0 ? void 0 : user.id) || '', createdByName: (user === null || user === void 0 ? void 0 : user.name) || '', modifiedBy: (user === null || user === void 0 ? void 0 : user.id) || '', modifiedByName: (user === null || user === void 0 ? void 0 : user.name) || '' }, values));
40
- }
41
- }
42
-
43
- class VasAccountObjectModel extends VasBaseModel {
44
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account) {
45
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName);
46
- this.id = id;
47
- this.created = created;
48
- this.serverCreated = serverCreated;
49
- this.createdBy = createdBy;
50
- this.modified = modified;
51
- this.serverModified = serverModified;
52
- this.modifiedBy = modifiedBy;
53
- this.createdByName = createdByName;
54
- this.modifiedByName = modifiedByName;
55
- this.account = account;
56
- }
57
- toApiDto(options) {
58
- return {
59
- id: this.id,
60
- created: this.created,
61
- modified: this.modified
62
- };
63
- }
64
- }
65
-
66
- var VasAccountIndexingMode;
67
- (function (VasAccountIndexingMode) {
68
- VasAccountIndexingMode[VasAccountIndexingMode["DISABLED"] = 0] = "DISABLED";
69
- VasAccountIndexingMode[VasAccountIndexingMode["ON_CHANGE"] = 1] = "ON_CHANGE";
70
- VasAccountIndexingMode[VasAccountIndexingMode["ON_REPORT"] = 2] = "ON_REPORT";
71
- })(VasAccountIndexingMode || (VasAccountIndexingMode = {}));
72
-
73
- class VasRestrictedAccountObjectModel extends VasAccountObjectModel {
74
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup) {
75
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account);
76
- this.id = id;
77
- this.created = created;
78
- this.serverCreated = serverCreated;
79
- this.createdBy = createdBy;
80
- this.modified = modified;
81
- this.serverModified = serverModified;
82
- this.modifiedBy = modifiedBy;
83
- this.createdByName = createdByName;
84
- this.modifiedByName = modifiedByName;
85
- this.account = account;
86
- this.accessGroup = accessGroup;
87
- }
88
- toApiDto(options) {
89
- return Object.assign(Object.assign({}, super.toApiDto(options)), { accessGroup: this.accessGroup });
90
- }
91
- }
92
-
93
- class VasBranchModel extends VasRestrictedAccountObjectModel {
94
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, branchType, storeCode, address, city, postcode, email, locationManager, areaManager, regionalDirector, salesManager, cluster, hourWeekdays, hourSaturday, hourSunday, exceptions, active) {
95
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
96
- this.id = id;
97
- this.created = created;
98
- this.serverCreated = serverCreated;
99
- this.createdBy = createdBy;
100
- this.modified = modified;
101
- this.serverModified = serverModified;
102
- this.modifiedBy = modifiedBy;
103
- this.createdByName = createdByName;
104
- this.modifiedByName = modifiedByName;
105
- this.account = account;
106
- this.accessGroup = accessGroup;
107
- this.branchType = branchType;
108
- this.storeCode = storeCode;
109
- this.address = address;
110
- this.city = city;
111
- this.postcode = postcode;
112
- this.email = email;
113
- this.locationManager = locationManager;
114
- this.areaManager = areaManager;
115
- this.regionalDirector = regionalDirector;
116
- this.salesManager = salesManager;
117
- this.cluster = cluster;
118
- this.hourWeekdays = hourWeekdays;
119
- this.hourSaturday = hourSaturday;
120
- this.hourSunday = hourSunday;
121
- this.exceptions = exceptions;
122
- this.active = active;
123
- }
124
- static fromDto(dto) {
125
- return new VasBranchModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', dto.branchType || '', dto.storeCode || '', dto.address || '', dto.city || '', dto.postcode || '', dto.email || '', dto.locationManager || undefined, dto.areaManager || undefined, dto.regionalDirector || undefined, dto.salesManager || undefined, dto.cluster || '', dto.hourWeekdays || [], dto.hourSaturday || [], dto.hourSunday || [], dto.exceptions || '', dto.active || true);
126
- }
127
- toDto() {
128
- return {
129
- id: this.id,
130
- created: this.created,
131
- serverCreated: this.serverCreated,
132
- createdBy: this.createdBy,
133
- modified: this.modified,
134
- serverModified: this.serverModified,
135
- modifiedBy: this.modifiedBy,
136
- createdByName: this.createdByName,
137
- modifiedByName: this.modifiedByName,
138
- account: this.account,
139
- accessGroup: this.accessGroup,
140
- branchType: this.branchType,
141
- storeCode: this.storeCode,
142
- address: this.address,
143
- city: this.city,
144
- postcode: this.postcode,
145
- email: this.email,
146
- locationManager: this.locationManager,
147
- areaManager: this.areaManager,
148
- regionalDirector: this.regionalDirector,
149
- salesManager: this.salesManager,
150
- cluster: this.cluster,
151
- hourWeekdays: this.hourWeekdays,
152
- hourSaturday: this.hourSaturday,
153
- hourSunday: this.hourSunday,
154
- exceptions: this.exceptions,
155
- active: this.active
156
- };
157
- }
158
- }
159
-
160
- /**
161
- * Return an object with only the properties specified by key(s)
162
- *
163
- * @param obj object to be processed
164
- * @param omitKey key or array of keys to be kept
165
- */
166
- const only = (obj, omitKey) => {
167
- return Object.keys(obj).reduce((result, key) => {
168
- if (Array.isArray(omitKey)) {
169
- if (omitKey.includes(key)) {
170
- result[key] = obj[key];
171
- }
172
- }
173
- else {
174
- if (omitKey === key) {
175
- result[key] = obj[key];
176
- }
177
- }
178
- return result;
179
- }, {});
180
- };
181
-
182
- class VasContactModel extends VasRestrictedAccountObjectModel {
183
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, contactType, name, email, mobile, phone, address, address2, address3, billingCode, business, fax, vatNumber, website) {
184
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
185
- this.id = id;
186
- this.created = created;
187
- this.serverCreated = serverCreated;
188
- this.createdBy = createdBy;
189
- this.modified = modified;
190
- this.serverModified = serverModified;
191
- this.modifiedBy = modifiedBy;
192
- this.createdByName = createdByName;
193
- this.modifiedByName = modifiedByName;
194
- this.account = account;
195
- this.accessGroup = accessGroup;
196
- this.contactType = contactType;
197
- this.name = name;
198
- this.email = email;
199
- this.mobile = mobile;
200
- this.phone = phone;
201
- this.address = address;
202
- this.address2 = address2;
203
- this.address3 = address3;
204
- this.billingCode = billingCode;
205
- this.business = business;
206
- this.fax = fax;
207
- this.vatNumber = vatNumber;
208
- this.website = website;
209
- }
210
- static fromDto(dto) {
211
- return new VasContactModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', dto.contactType || '', dto.name || '', dto.email || '', dto.mobile || '', dto.phone || '', dto.address || '', dto.address2 || '', dto.address3 || '', dto.billingCode || '', dto.business || '', dto.fax || '', dto.vatNumber || '', dto.website || '');
212
- }
213
- toDto() {
214
- return {
215
- id: this.id,
216
- created: this.created,
217
- serverCreated: this.serverCreated,
218
- createdBy: this.createdBy,
219
- modified: this.modified,
220
- serverModified: this.serverModified,
221
- modifiedBy: this.modifiedBy,
222
- createdByName: this.createdByName,
223
- modifiedByName: this.modifiedByName,
224
- account: this.account,
225
- accessGroup: this.accessGroup,
226
- contactType: this.contactType,
227
- name: this.name,
228
- email: this.email,
229
- mobile: this.mobile,
230
- phone: this.phone,
231
- address: this.address,
232
- address2: this.address2,
233
- address3: this.address3,
234
- billingCode: this.billingCode,
235
- business: this.business,
236
- fax: this.fax,
237
- vatNumber: this.vatNumber,
238
- website: this.website,
239
- };
240
- }
241
- toApiDto(options) {
242
- return Object.assign(Object.assign({}, super.toApiDto()), { contactType: this.contactType || '~', name: this.name || '~', email: this.email || '~', mobile: this.mobile || '~', phone: this.phone || '~', address: this.address || '~', address2: this.address2 || '~', address3: this.address3 || '~', billingCode: this.billingCode || '~', business: this.business || '~', fax: this.fax || '~', vatNumber: this.vatNumber || '~', website: this.website || '~' });
243
- }
244
- static toApiPatchDto(contact) {
245
- return only(contact, [
246
- 'created',
247
- 'modified',
248
- 'accessGroup',
249
- 'contactType',
250
- 'name',
251
- 'email',
252
- 'mobile',
253
- 'phone',
254
- 'address',
255
- 'address2',
256
- 'address3',
257
- 'billingCode',
258
- 'business',
259
- 'fax',
260
- 'vatNumber',
261
- 'website'
262
- ]);
263
- }
264
- }
265
-
266
- /**
267
- * VasControlTypeModel
268
- */
269
- class VasControlTypeModel extends VasBaseModel {
270
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, name) {
271
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName);
272
- this.id = id;
273
- this.created = created;
274
- this.serverCreated = serverCreated;
275
- this.createdBy = createdBy;
276
- this.modified = modified;
277
- this.serverModified = serverModified;
278
- this.modifiedBy = modifiedBy;
279
- this.createdByName = createdByName;
280
- this.modifiedByName = modifiedByName;
281
- this.name = name;
282
- }
283
- /**
284
- * @return VasControlTypeModel
285
- */
286
- static empty() {
287
- return new VasControlTypeModel('', '', '', '', '', '', '', '', '', '');
288
- }
289
- /**
290
- * @param {VasControlTypeDto} dto
291
- * @return {VasControlTypeModel}
292
- */
293
- static fromDto(dto) {
294
- return new VasControlTypeModel(
295
- // eslint-disable-next-line new-cap
296
- dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.name || '');
297
- }
298
- /**
299
- * @return {VasControlTypeDto}
300
- */
301
- toDto() {
302
- return {
303
- id: this.id,
304
- created: this.created,
305
- serverCreated: this.serverCreated,
306
- createdBy: this.createdBy,
307
- modified: this.modified,
308
- serverModified: this.serverModified,
309
- modifiedBy: this.modifiedBy,
310
- createdByName: this.createdByName,
311
- modifiedByName: this.modifiedByName,
312
- name: this.name
313
- };
314
- }
315
- }
316
-
317
- /**
318
- * ControlModel
319
- */
320
- class VasControlModel extends VasRestrictedAccountObjectModel {
321
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, controlType, group, validators, name, title, linkable, sequence, description, defaultValue, config, descriptionImage, portalEnabled) {
322
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
323
- this.id = id;
324
- this.created = created;
325
- this.serverCreated = serverCreated;
326
- this.createdBy = createdBy;
327
- this.modified = modified;
328
- this.serverModified = serverModified;
329
- this.modifiedBy = modifiedBy;
330
- this.createdByName = createdByName;
331
- this.modifiedByName = modifiedByName;
332
- this.account = account;
333
- this.accessGroup = accessGroup;
334
- this.controlType = controlType;
335
- this.group = group;
336
- this.validators = validators;
337
- this.name = name;
338
- this.title = title;
339
- this.linkable = linkable;
340
- this.sequence = sequence;
341
- this.description = description;
342
- this.defaultValue = defaultValue;
343
- this.config = config;
344
- this.descriptionImage = descriptionImage;
345
- this.portalEnabled = portalEnabled;
346
- this.controlTypeId = '';
347
- if (typeof controlType === 'string') {
348
- this.controlTypeId = controlType;
349
- }
350
- else {
351
- this.controlTypeId = controlType.id;
352
- }
353
- }
354
- get controlTypeName() {
355
- var _a;
356
- return ((_a = this.controlType) === null || _a === void 0 ? void 0 : _a.name) || '';
357
- }
358
- /**
359
- * The defaultValue property is returned from the api as a string or number,
360
- * in the case of string, it maybe a json. This getter will return an
361
- * object if the value is a json string
362
- */
363
- get defaultValueDecoded() {
364
- if (this.defaultValue === '' && this.controlType) {
365
- switch (this.controlTypeName) {
366
- case 'branch':
367
- case 'camera':
368
- case 'contact': {
369
- return {};
370
- }
371
- case 'toggle': {
372
- return {
373
- checked: false, comment: ''
374
- };
375
- }
376
- }
377
- }
378
- return this.parseMaybeJson(this.defaultValue);
379
- }
380
- /**
381
- * Returns the name of this control to be used in the report templates
382
- * i.e. fields.foo -> foo
383
- * @return {string}
384
- */
385
- get reportTemplateName() {
386
- return this.name.replace(/^fields\./, '');
387
- }
388
- /**
389
- * @return {string}
390
- */
391
- get safeName() {
392
- return this.name;
393
- }
394
- /**
395
- * @return {VasControlModel}
396
- */
397
- static empty() {
398
- return VasControlModel.fromDto({
399
- // eslint-disable-next-line new-cap
400
- id: UUID.UUID()
401
- });
402
- }
403
- /**
404
- * @param {VasControlDto} dto
405
- * @return {VasControlModel}
406
- */
407
- static fromDto(dto) {
408
- const handleControlType = (c) => {
409
- if (c === undefined) {
410
- return VasControlTypeModel.empty();
411
- }
412
- else if (typeof c === 'string') {
413
- return VasControlTypeModel.fromDto({ id: c });
414
- }
415
- else {
416
- return VasControlTypeModel.fromDto(c);
417
- }
418
- };
419
- return new VasControlModel(
420
- // eslint-disable-next-line new-cap
421
- dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', handleControlType(dto.controlType), dto.group || '', dto.validators || [], dto.name || '', dto.title || '', dto.linkable || false, dto.sequence || 0, dto.description || '', dto.defaultValue || '', typeof dto.config === 'string' ?
422
- JSON.parse(dto.config || '{}') :
423
- dto.config, dto.descriptionImage || '', dto.portalEnabled || false);
424
- }
425
- /**
426
- * @param {any} value the value to be parsed
427
- * @return {VasFieldDtoValue} the parsed value
428
- */
429
- parseMaybeJson(value) {
430
- if (typeof value !== 'string') {
431
- return value;
432
- }
433
- try {
434
- return JSON.parse(value);
435
- }
436
- catch (e) {
437
- return value;
438
- }
439
- }
440
- /**
441
- * @return {VasControlDto}
442
- */
443
- toDto() {
444
- return {
445
- id: this.id,
446
- created: this.created,
447
- serverCreated: this.serverCreated,
448
- createdBy: this.createdBy,
449
- modified: this.modified,
450
- serverModified: this.serverModified,
451
- modifiedBy: this.modifiedBy,
452
- createdByName: this.createdByName,
453
- modifiedByName: this.modifiedByName,
454
- account: this.account,
455
- accessGroup: this.accessGroup,
456
- controlType: this.controlType.toDto(),
457
- group: this.group,
458
- validators: this.validators,
459
- name: this.name,
460
- title: this.title,
461
- linkable: this.linkable,
462
- sequence: this.sequence,
463
- description: this.description,
464
- defaultValue: this.defaultValue,
465
- config: JSON.stringify(this.config),
466
- descriptionImage: this.descriptionImage,
467
- portalEnabled: this.portalEnabled
468
- };
469
- }
470
- toApiDto(options) {
471
- return Object.assign(Object.assign({}, super.toApiDto()), { title: this.title || '~', name: this.name || '~', portalEnabled: this.portalEnabled, sequence: this.sequence, description: this.description || '~', defaultValue: this.defaultValue, config: JSON.stringify(this.config), controlType: this.controlType.id, group: this.group, validators: this.validators, linkable: this.linkable });
472
- }
473
- static toApiPatchDto(item) {
474
- return only(item, [
475
- 'created',
476
- 'modified',
477
- 'title',
478
- 'name',
479
- 'portalEnabled',
480
- 'sequence',
481
- 'description',
482
- 'defaultValue',
483
- 'config',
484
- 'controlType',
485
- 'group',
486
- 'validators',
487
- 'linkable',
488
- ]);
489
- }
490
- }
491
-
492
- /**
493
- * VasJobDataModel
494
- */
495
- class VasJobDataModel extends VasAccountObjectModel {
496
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job) {
497
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account);
498
- this.id = id;
499
- this.created = created;
500
- this.serverCreated = serverCreated;
501
- this.createdBy = createdBy;
502
- this.modified = modified;
503
- this.serverModified = serverModified;
504
- this.modifiedBy = modifiedBy;
505
- this.createdByName = createdByName;
506
- this.modifiedByName = modifiedByName;
507
- this.account = account;
508
- this.job = job;
509
- }
510
- }
511
-
512
- /**
513
- * Prepares the value to be sent to the API. The api will only accept strings,
514
- * numbers and booleans, thus if we have an array or object, we need to JSON
515
- * encode it
516
- * @param {VasFieldDto} value
517
- * @return {string | number | boolean}
518
- * @protected
519
- */
520
- const prepareFieldApiValue = (value) => {
521
- switch (typeof value) {
522
- case 'object': {
523
- return JSON.stringify(value);
524
- }
525
- case 'boolean': {
526
- return value;
527
- }
528
- case 'string': {
529
- return value;
530
- }
531
- case 'number': {
532
- return value;
533
- }
534
- default: {
535
- return '';
536
- }
537
- }
538
- };
539
- /**
540
- * VasFieldModel
541
- */
542
- class VasFieldModel extends VasJobDataModel {
543
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job, control, fieldJobPointers, value, version, controlName, controlTitle, controlTypeName) {
544
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job);
545
- this.id = id;
546
- this.created = created;
547
- this.serverCreated = serverCreated;
548
- this.createdBy = createdBy;
549
- this.modified = modified;
550
- this.serverModified = serverModified;
551
- this.modifiedBy = modifiedBy;
552
- this.createdByName = createdByName;
553
- this.modifiedByName = modifiedByName;
554
- this.account = account;
555
- this.job = job;
556
- this.control = control;
557
- this.fieldJobPointers = fieldJobPointers;
558
- this.value = value;
559
- this.version = version;
560
- this.controlName = controlName;
561
- this.controlTitle = controlTitle;
562
- this.controlTypeName = controlTypeName;
563
- }
564
- /**
565
- * @param {VasFieldDto} fieldDto
566
- * @return {VasFieldModel}
567
- */
568
- static fromDto(fieldDto) {
569
- return new VasFieldModel(fieldDto.id || '', fieldDto.created || '', fieldDto.serverCreated || '', fieldDto.createdBy || '', fieldDto.modified || '', fieldDto.serverModified || '', fieldDto.modifiedBy || '', fieldDto.createdByName || '', fieldDto.modifiedByName || '', fieldDto.account || '', fieldDto.job || '', fieldDto.control || '', fieldDto.fieldJobPointers || [], fieldDto.value || '', fieldDto.version || 0, fieldDto.controlName || '', fieldDto.controlTitle || '', fieldDto.controlTypeName || '');
570
- }
571
- /**
572
- * @return {VasFieldDto}
573
- */
574
- toDto() {
575
- return {
576
- id: this.id,
577
- created: this.created,
578
- serverCreated: this.serverCreated,
579
- createdBy: this.createdBy,
580
- modified: this.modified,
581
- serverModified: this.serverModified,
582
- modifiedBy: this.modifiedBy,
583
- createdByName: this.createdByName,
584
- modifiedByName: this.modifiedByName,
585
- account: this.account,
586
- job: this.job,
587
- control: this.control,
588
- fieldJobPointers: this.fieldJobPointers,
589
- value: this.value,
590
- version: this.version,
591
- controlName: this.controlName,
592
- controlTitle: this.controlTitle,
593
- controlTypeName: this.controlTypeName,
594
- };
595
- }
596
- /**
597
- * @return {object}
598
- */
599
- toApiDto() {
600
- return Object.assign(Object.assign({}, super.toApiDto()), { control: this.control, value: prepareFieldApiValue(this.value) });
601
- }
602
- static toApiPatchDto(item) {
603
- const clone = JSON.parse(JSON.stringify(item));
604
- if (clone.value !== undefined && clone.value !== null) {
605
- clone.value = prepareFieldApiValue(clone.value);
606
- }
607
- else {
608
- clone.value = '';
609
- }
610
- return only(clone, [
611
- 'created',
612
- 'modified',
613
- 'value'
614
- ]);
615
- }
616
- }
617
-
618
- function isFileDto(object) {
619
- return object instanceof Object
620
- && 'url' in object
621
- && 'uri' in object
622
- && 'message' in object
623
- && 'status' in object
624
- && 'controlPath' in object;
625
- }
626
-
627
- /**
628
- * VasFileDto
629
- */
630
- class VasFileModel extends VasJobDataModel {
631
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job, name, fileSize, mimeType, sequence, config, url, controlPath, message, status, uri) {
632
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job);
633
- this.id = id;
634
- this.created = created;
635
- this.serverCreated = serverCreated;
636
- this.createdBy = createdBy;
637
- this.modified = modified;
638
- this.serverModified = serverModified;
639
- this.modifiedBy = modifiedBy;
640
- this.createdByName = createdByName;
641
- this.modifiedByName = modifiedByName;
642
- this.account = account;
643
- this.job = job;
644
- this.name = name;
645
- this.fileSize = fileSize;
646
- this.mimeType = mimeType;
647
- this.sequence = sequence;
648
- this.config = config;
649
- this.url = url;
650
- this.controlPath = controlPath;
651
- this.message = message;
652
- this.status = status;
653
- this.uri = uri;
654
- }
655
- static empty() {
656
- return new VasFileModel('', '', '', '', '', '', '', '', '', '', '', '', 0, '', 0, {
657
- displayAs: 'grid',
658
- embedLink: false,
659
- group: 'photo',
660
- description: '',
661
- displayedName: '',
662
- rotation: 0
663
- }, '', '', '', 'NEW', '');
664
- }
665
- static fromDto(dto) {
666
- return new VasFileModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.job || '', dto.name || '', dto.fileSize || 0, dto.mimeType || '', dto.sequence || 0, VasFileModel.parseConfig(dto.config), dto.url || '', dto.controlPath || '', dto.message || '', dto.status || 'NEW', dto.uri || '');
667
- }
668
- static parseConfig(config = '') {
669
- try {
670
- return JSON.parse(config);
671
- }
672
- catch (e) {
673
- return {
674
- displayAs: 'grid',
675
- embedLink: false,
676
- group: 'photo',
677
- description: '',
678
- displayedName: '',
679
- rotation: 0
680
- };
681
- }
682
- }
683
- /**
684
- * @return {VasFileDto}
685
- */
686
- toDto() {
687
- return {
688
- id: this.id,
689
- created: this.created,
690
- serverCreated: this.serverCreated,
691
- createdBy: this.createdBy,
692
- modified: this.modified,
693
- serverModified: this.serverModified,
694
- modifiedBy: this.modifiedBy,
695
- createdByName: this.createdByName,
696
- modifiedByName: this.modifiedByName,
697
- account: this.account,
698
- job: this.job,
699
- name: this.name,
700
- fileSize: this.fileSize,
701
- mimeType: this.mimeType,
702
- sequence: this.sequence,
703
- config: this.stringifyConfig(this.config),
704
- url: this.url,
705
- controlPath: this.controlPath,
706
- message: this.message,
707
- status: this.status,
708
- uri: this.uri,
709
- };
710
- }
711
- stringifyConfig(config) {
712
- if (!config) {
713
- return JSON.stringify({
714
- displayAs: 'grid',
715
- embedLink: false,
716
- group: 'photo',
717
- description: '',
718
- displayedName: '',
719
- rotation: 0
720
- });
721
- }
722
- try {
723
- return JSON.stringify(config);
724
- }
725
- catch (e) {
726
- console.warn(e);
727
- return '';
728
- }
729
- }
730
- toApiDto(options = { contentUploaded: false }) {
731
- const apiDto = Object.assign(Object.assign({}, super.toApiDto()), { name: this.name || '~', mimeType: this.mimeType || '~', sequence: this.safeNumber(this.sequence), config: JSON.stringify(this.config) });
732
- if (options.contentUploaded) {
733
- apiDto['original'] = this.id;
734
- }
735
- return apiDto;
736
- }
737
- safeNumber(value) {
738
- if (!Number.isFinite(value)) {
739
- return 0;
740
- }
741
- return value;
742
- }
743
- static toApiPatchDto(item) {
744
- return only(item, [
745
- 'created',
746
- 'modified',
747
- 'name',
748
- 'sequence',
749
- 'config'
750
- ]);
751
- }
752
- }
753
-
754
- class VasUserModel extends VasBaseModel {
755
- constructor(id, created = '', serverCreated = '', createdBy = '', modified = '', serverModified = '', modifiedBy = '', createdByName, modifiedByName, email, name, username, memberships, instructionProviders) {
756
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName);
757
- this.id = id;
758
- this.created = created;
759
- this.serverCreated = serverCreated;
760
- this.createdBy = createdBy;
761
- this.modified = modified;
762
- this.serverModified = serverModified;
763
- this.modifiedBy = modifiedBy;
764
- this.createdByName = createdByName;
765
- this.modifiedByName = modifiedByName;
766
- this.email = email;
767
- this.name = name;
768
- this.username = username;
769
- this.memberships = memberships;
770
- this.instructionProviders = instructionProviders;
771
- }
772
- static fromDto(dto) {
773
- return new VasUserModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.email || '', dto.name || '', dto.username || '', dto.memberships || [], dto.instructionProviders || []);
774
- }
775
- toDto() {
776
- return {
777
- id: this.id,
778
- created: this.created,
779
- serverCreated: this.serverCreated,
780
- createdBy: this.createdBy,
781
- modified: this.modified,
782
- serverModified: this.serverModified,
783
- modifiedBy: this.modifiedBy,
784
- createdByName: this.createdByName,
785
- modifiedByName: this.modifiedByName,
786
- email: this.email,
787
- name: this.name,
788
- username: this.username,
789
- memberships: this.memberships,
790
- instructionProviders: this.instructionProviders
791
- };
792
- }
793
- }
794
-
795
- class VasFireUserModel extends VasUserModel {
796
- constructor(id, created = '', serverCreated = '', createdBy = '', modified = '', serverModified = '', modifiedBy = '', createdByName, modifiedByName, email, name, username, memberships, instructionProviders, accounts, tokens, topics, language, displayName) {
797
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, email, name, username, memberships, instructionProviders);
798
- this.id = id;
799
- this.created = created;
800
- this.serverCreated = serverCreated;
801
- this.createdBy = createdBy;
802
- this.modified = modified;
803
- this.serverModified = serverModified;
804
- this.modifiedBy = modifiedBy;
805
- this.createdByName = createdByName;
806
- this.modifiedByName = modifiedByName;
807
- this.email = email;
808
- this.name = name;
809
- this.username = username;
810
- this.memberships = memberships;
811
- this.instructionProviders = instructionProviders;
812
- this.accounts = accounts;
813
- this.tokens = tokens;
814
- this.topics = topics;
815
- this.language = language;
816
- this.displayName = displayName;
817
- }
818
- static fromDto(dto) {
819
- return new VasFireUserModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.email || '', dto.name || '', dto.username || '', dto.memberships || [], dto.instructionProviders || [], dto.accounts || {}, dto.tokens || [], dto.topics || [], dto.language || '', dto.displayName || '');
820
- }
821
- static newUser(uid, displayName, email) {
822
- return new VasFireUserModel(uid, moment().toISOString(), moment().toISOString(), uid, moment().toISOString(), moment().toISOString(), uid, '', '', email, displayName, email, [], [], {}, [], [], '', displayName);
823
- }
824
- toDto() {
825
- return {
826
- id: this.id,
827
- created: this.created,
828
- serverCreated: this.serverCreated,
829
- createdBy: this.createdBy,
830
- modified: this.modified,
831
- serverModified: this.serverModified,
832
- modifiedBy: this.modifiedBy,
833
- createdByName: this.createdByName,
834
- modifiedByName: this.modifiedByName,
835
- email: this.email,
836
- name: this.name,
837
- username: this.username,
838
- memberships: this.memberships,
839
- instructionProviders: this.instructionProviders,
840
- accounts: this.accounts,
841
- tokens: this.tokens,
842
- topics: this.topics,
843
- language: this.language,
844
- displayName: this.displayName
845
- };
846
- }
847
- /**
848
- * Adds token to tokens list if it is not already present
849
- * @param token the new token
850
- */
851
- addToken(token) {
852
- if (this.tokens.includes(token)) {
853
- return;
854
- }
855
- this.tokens.push(token);
856
- }
857
- /**
858
- * Remove token from tokens list
859
- * @param token the token to remove
860
- */
861
- removeToken(token) {
862
- this.tokens = this.tokens.filter(t => t !== token);
863
- }
864
- /**
865
- * Resets the tokens list
866
- */
867
- resetTokens() {
868
- this.tokens = [];
869
- }
870
- /**
871
- * Adds topic to topics list if it is not already present
872
- * @param topic the new token
873
- */
874
- addTopic(topic) {
875
- if (this.topics.includes(topic)) {
876
- return;
877
- }
878
- this.topics.push(topic);
879
- }
880
- /**
881
- * Remove topic from topic list
882
- * @param topic the topic to remove
883
- */
884
- removeTopic(topic) {
885
- this.topics = this.topics.filter(t => t !== topic);
886
- }
887
- /**
888
- * Resets the topic list
889
- */
890
- resetTopics() {
891
- this.topics = [];
892
- }
893
- }
894
-
895
- class VasFormConfigModel {
896
- constructor(emailRecipients, actions) {
897
- this.emailRecipients = emailRecipients;
898
- this.actions = actions;
899
- }
900
- toDto() {
901
- return {
902
- emailRecipients: this.emailRecipients,
903
- actions: this.actions
904
- };
905
- }
906
- toJsonString() {
907
- return JSON.stringify(this.toDto());
908
- }
909
- static create() {
910
- return new VasFormConfigModel();
911
- }
912
- static fromDto(dto) {
913
- return new VasFormConfigModel(dto.emailRecipients, dto.actions);
914
- }
915
- static fromJsonString(value) {
916
- try {
917
- const dto = JSON.parse(value || '{}');
918
- return VasFormConfigModel.fromDto(dto);
919
- }
920
- catch (e) {
921
- return VasFormConfigModel.create();
922
- }
923
- }
924
- }
925
-
926
- /**
927
- * GroupModel
928
- */
929
- class VasGroupModel extends VasRestrictedAccountObjectModel {
930
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, name, title, description, sequence, includeInSummary, forms, visibilityControl, visibleIfEquals, controls, scoreWeight) {
931
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
932
- this.id = id;
933
- this.created = created;
934
- this.serverCreated = serverCreated;
935
- this.createdBy = createdBy;
936
- this.modified = modified;
937
- this.serverModified = serverModified;
938
- this.modifiedBy = modifiedBy;
939
- this.createdByName = createdByName;
940
- this.modifiedByName = modifiedByName;
941
- this.account = account;
942
- this.accessGroup = accessGroup;
943
- this.name = name;
944
- this.title = title;
945
- this.description = description;
946
- this.sequence = sequence;
947
- this.includeInSummary = includeInSummary;
948
- this.forms = forms;
949
- this.visibilityControl = visibilityControl;
950
- this.visibleIfEquals = visibleIfEquals;
951
- this.controls = controls;
952
- this.scoreWeight = scoreWeight;
953
- }
954
- /**
955
- * @param {VasGroupDto} dto
956
- * @return {VasGroupModel}
957
- */
958
- static fromDto(dto) {
959
- return new VasGroupModel(
960
- // eslint-disable-next-line new-cap
961
- dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', dto.name || '', dto.title || '', dto.description || '', dto.sequence || 0, dto.includeInSummary || false, dto.forms || [], dto.visibilityControl || '', dto.visibleIfEquals || '', (dto.controls || [])
962
- .filter(control => control.name.startsWith('fields.'))
963
- .sort((a, b) => a.sequence - b.sequence)
964
- .map(c => VasControlModel.fromDto(c)), dto.scoreWeight || 1);
965
- }
966
- /**
967
- * @param {Array<VasControlModel>} valuesByControlId
968
- * @return {boolean}
969
- */
970
- isVisible(valuesByControlId) {
971
- if (!this.visibilityControl || !this.visibleIfEquals) {
972
- return true;
973
- }
974
- const control = valuesByControlId
975
- .find(c => c.id === this.visibilityControl);
976
- if (!control) {
977
- console.warn(`control with id ${this.visibilityControl} not found`);
978
- return true;
979
- }
980
- return (control.value || '').toString() === this.visibleIfEquals;
981
- }
982
- /**
983
- * @return {VasGroupDto}
984
- */
985
- toDto() {
986
- return {
987
- id: this.id,
988
- created: this.created,
989
- serverCreated: this.serverCreated,
990
- createdBy: this.createdBy,
991
- modified: this.modified,
992
- serverModified: this.serverModified,
993
- modifiedBy: this.modifiedBy,
994
- createdByName: this.createdByName,
995
- modifiedByName: this.modifiedByName,
996
- account: this.account,
997
- accessGroup: this.accessGroup,
998
- name: this.name,
999
- title: this.title,
1000
- description: this.description,
1001
- sequence: this.sequence,
1002
- includeInSummary: this.includeInSummary,
1003
- forms: this.forms,
1004
- visibilityControl: this.visibilityControl,
1005
- visibleIfEquals: this.visibleIfEquals,
1006
- controls: this.controls.map(control => control.toDto()),
1007
- scoreWeight: this.scoreWeight
1008
- };
1009
- }
1010
- toApiDto(options) {
1011
- return Object.assign(Object.assign({}, super.toApiDto(options)), { name: this.name || '~', title: this.title || '~', sequence: this.sequence || 0, includeInSummary: this.includeInSummary });
1012
- }
1013
- static toApiPatchDto(item) {
1014
- return only(item, [
1015
- 'created',
1016
- 'modified',
1017
- 'name',
1018
- 'title',
1019
- 'sequence',
1020
- 'includeInSummary'
1021
- ]);
1022
- }
1023
- }
1024
-
1025
- /**
1026
- * VasFormModel
1027
- */
1028
- class VasFormModel extends VasRestrictedAccountObjectModel {
1029
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, jobType, title, description, groups, dynamicDescriptor, indexName, pipelineName, config, geoLocationEnabled, filesEnabled) {
1030
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
1031
- this.id = id;
1032
- this.created = created;
1033
- this.serverCreated = serverCreated;
1034
- this.createdBy = createdBy;
1035
- this.modified = modified;
1036
- this.serverModified = serverModified;
1037
- this.modifiedBy = modifiedBy;
1038
- this.createdByName = createdByName;
1039
- this.modifiedByName = modifiedByName;
1040
- this.account = account;
1041
- this.accessGroup = accessGroup;
1042
- this.jobType = jobType;
1043
- this.title = title;
1044
- this.description = description;
1045
- this.groups = groups;
1046
- this.dynamicDescriptor = dynamicDescriptor;
1047
- this.indexName = indexName;
1048
- this.pipelineName = pipelineName;
1049
- this.config = config;
1050
- this.geoLocationEnabled = geoLocationEnabled;
1051
- this.filesEnabled = filesEnabled;
1052
- }
1053
- /**
1054
- * Returns the name of this form in a "safe" way, i.e. no spaces, special
1055
- * characters
1056
- * @return {string}
1057
- */
1058
- get safeTitle() {
1059
- return this.title
1060
- .replace(/[^a-z0-9]/gi, '-')
1061
- .replace(/-+/g, '-')
1062
- .toLowerCase();
1063
- }
1064
- /**
1065
- * The VAS API response for Form will inline Group and Control but not
1066
- * ControlType. This method is a help which will allows us to construct an
1067
- * instance of VasFormModel with the ControlType model set appropriately into
1068
- * each VasControlModel
1069
- * @param {VasFormDto} formDto
1070
- * @param {Array<VasControlTypeDto>} controlTypeDtos
1071
- * @return {VasFormModel}
1072
- * @deprecated vas-rest has been updated to inline control types into the
1073
- * control so this method is no longer required. use VasFormModel.fromDto()
1074
- */
1075
- static fromApiResponse(formDto, controlTypeDtos) {
1076
- const controlTypeModels = controlTypeDtos
1077
- .map(ctDto => VasControlTypeModel.fromDto(ctDto));
1078
- const formModel = VasFormModel.fromDto(formDto);
1079
- formModel.groups
1080
- .forEach(group => {
1081
- group.controls
1082
- .forEach(control => {
1083
- // Note that we are forcing types here. This is because we have
1084
- // updated the typings for ControlModel and ControlDto to reflect
1085
- // the fact that VASREST is updating the response from certain
1086
- // controllers to inline ControlType into the Control. Consumers of
1087
- // the library will know what version of the API they are consuming
1088
- // so can decide when to migrate away from fromApiResponse, and can
1089
- // use fromDto instead
1090
- control.controlType = controlTypeModels
1091
- .find(ct => ct.id === (control.controlTypeId));
1092
- });
1093
- });
1094
- return formModel;
1095
- }
1096
- static empty() {
1097
- return VasFormModel.fromDto({});
1098
- }
1099
- /**
1100
- * @param {VasFormDto} dto
1101
- * @return {VasFormModel}
1102
- */
1103
- static fromDto(dto) {
1104
- return new VasFormModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', dto.jobType || '', dto.title || '', dto.description || '', (dto.groups || [])
1105
- .sort((a, b) => a.sequence - b.sequence)
1106
- .map(g => VasGroupModel.fromDto(g)), dto.dynamicDescriptor || '', dto.indexName || '', dto.pipelineName || '', VasFormConfigModel.fromJsonString(dto.config), dto.geoLocationEnabled || false, dto.filesEnabled || false);
1107
- }
1108
- /**
1109
- * @param {string} id
1110
- * @return {VasControlModel | undefined}
1111
- */
1112
- findControlModelById(id) {
1113
- let result;
1114
- this.groups
1115
- .find(group => group.controls
1116
- .find(control => {
1117
- if (control.id !== id) {
1118
- return;
1119
- }
1120
- result = control;
1121
- return true;
1122
- }));
1123
- return result;
1124
- }
1125
- /**
1126
- *
1127
- * @param {string} name
1128
- * @return {VasControlModel | undefined}
1129
- */
1130
- findControlModelByName(name) {
1131
- let result;
1132
- this.groups
1133
- .find(group => group.controls
1134
- .find(control => {
1135
- if (control.name !== name) {
1136
- return;
1137
- }
1138
- result = control;
1139
- return true;
1140
- }));
1141
- return result;
1142
- }
1143
- /**
1144
- *
1145
- * @return {Array<Array<string>>}
1146
- */
1147
- getCameraControlPaths() {
1148
- const paths = [];
1149
- this.groups.forEach(group => {
1150
- group.controls.forEach(control => {
1151
- if (control.controlTypeName !== 'camera') {
1152
- return;
1153
- }
1154
- paths.push([group.name, control.safeName]);
1155
- });
1156
- });
1157
- return paths;
1158
- }
1159
- /**
1160
- * Return all Controls in the Form
1161
- */
1162
- getControls() {
1163
- return this.groups
1164
- .reduce((acc, g) => {
1165
- return acc.concat(g.controls);
1166
- }, []);
1167
- }
1168
- /**
1169
- * @param {VasJobModel} jobModel
1170
- * @return {Array<{id: string, value: VasFieldDtoValue}>}
1171
- */
1172
- getValuesByControlId(jobModel) {
1173
- const items = [];
1174
- this.groups
1175
- .forEach(group => {
1176
- group.controls
1177
- .forEach(control => {
1178
- items.push({
1179
- id: control.id,
1180
- value: jobModel.getValueByPath([group.name, control.safeName])
1181
- });
1182
- });
1183
- });
1184
- return items;
1185
- }
1186
- /**
1187
- * @return {VasFormDto}
1188
- */
1189
- toDto() {
1190
- return {
1191
- id: this.id,
1192
- created: this.created,
1193
- serverCreated: this.serverCreated,
1194
- createdBy: this.createdBy,
1195
- modified: this.modified,
1196
- serverModified: this.serverModified,
1197
- modifiedBy: this.modifiedBy,
1198
- createdByName: this.createdByName,
1199
- modifiedByName: this.modifiedByName,
1200
- account: this.account,
1201
- accessGroup: this.accessGroup,
1202
- jobType: this.jobType,
1203
- title: this.title,
1204
- description: this.description,
1205
- groups: this.groups.map(group => group.toDto()),
1206
- dynamicDescriptor: this.dynamicDescriptor,
1207
- indexName: this.indexName,
1208
- pipelineName: this.pipelineName,
1209
- config: this.config.toJsonString(),
1210
- geoLocationEnabled: this.geoLocationEnabled,
1211
- filesEnabled: this.filesEnabled
1212
- };
1213
- }
1214
- toApiDto(options) {
1215
- return Object.assign(Object.assign({}, super.toApiDto(options)), { title: this.title || '~', description: this.description || '~', jobType: this.jobType, config: this.config.toJsonString() });
1216
- }
1217
- static toApiPatchDto(item) {
1218
- return only(item, [
1219
- 'created',
1220
- 'modified',
1221
- 'title',
1222
- 'description',
1223
- 'jobType',
1224
- 'config'
1225
- ]);
1226
- }
1227
- }
1228
-
1229
- /**
1230
- * VasInstructionJobFieldModel
1231
- */
1232
- class VasInstructionJobFieldModel extends VasBaseModel {
1233
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, value, name, title, sequence, controlType) {
1234
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName);
1235
- this.id = id;
1236
- this.created = created;
1237
- this.serverCreated = serverCreated;
1238
- this.createdBy = createdBy;
1239
- this.modified = modified;
1240
- this.serverModified = serverModified;
1241
- this.modifiedBy = modifiedBy;
1242
- this.createdByName = createdByName;
1243
- this.modifiedByName = modifiedByName;
1244
- this.value = value;
1245
- this.name = name;
1246
- this.title = title;
1247
- this.sequence = sequence;
1248
- this.controlType = controlType;
1249
- }
1250
- static empty() {
1251
- return new VasInstructionJobFieldModel('', '', '', '', '', '', '', '', '', '', '', '', 0, '');
1252
- }
1253
- static fromDto(dto) {
1254
- return new VasInstructionJobFieldModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.value || '', dto.name || '', dto.title || '', dto.sequence || 0, dto.controlType || '');
1255
- }
1256
- toDto() {
1257
- return {
1258
- id: this.id,
1259
- created: this.created,
1260
- serverCreated: this.serverCreated,
1261
- createdBy: this.createdBy,
1262
- modified: this.modified,
1263
- serverModified: this.serverModified,
1264
- modifiedBy: this.modifiedBy,
1265
- createdByName: this.createdByName,
1266
- modifiedByName: this.modifiedByName,
1267
- value: this.value,
1268
- name: this.name,
1269
- title: this.title,
1270
- sequence: this.sequence,
1271
- controlType: this.controlType
1272
- };
1273
- }
1274
- }
1275
-
1276
- /**
1277
- * VasNoteModel
1278
- */
1279
- class VasNoteModel extends VasJobDataModel {
1280
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job, content, sensitive) {
1281
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job);
1282
- this.id = id;
1283
- this.created = created;
1284
- this.serverCreated = serverCreated;
1285
- this.createdBy = createdBy;
1286
- this.modified = modified;
1287
- this.serverModified = serverModified;
1288
- this.modifiedBy = modifiedBy;
1289
- this.createdByName = createdByName;
1290
- this.modifiedByName = modifiedByName;
1291
- this.account = account;
1292
- this.job = job;
1293
- this.content = content;
1294
- this.sensitive = sensitive;
1295
- }
1296
- /**
1297
- * @param dto VasNoteDto
1298
- * @return VasNoteModel
1299
- */
1300
- static fromDto(dto) {
1301
- return new VasNoteModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.job || '', dto.content || '', dto.sensitive || false);
1302
- }
1303
- /**
1304
- * @returns VasNoteDto
1305
- */
1306
- toDto() {
1307
- return {
1308
- id: this.id,
1309
- created: this.created,
1310
- serverCreated: this.serverCreated,
1311
- createdBy: this.createdBy,
1312
- modified: this.modified,
1313
- serverModified: this.serverModified,
1314
- modifiedBy: this.modifiedBy,
1315
- createdByName: this.createdByName,
1316
- modifiedByName: this.modifiedByName,
1317
- account: this.account,
1318
- job: this.job,
1319
- content: this.content,
1320
- sensitive: this.sensitive,
1321
- };
1322
- }
1323
- toApiDto(options) {
1324
- return Object.assign(Object.assign({}, super.toApiDto(options)), { content: this.content, sensitive: this.sensitive, created: this.created, modified: this.modified });
1325
- }
1326
- static toApiPatchDto(item) {
1327
- return only(item, [
1328
- 'created',
1329
- 'modified',
1330
- 'content',
1331
- 'sensitive'
1332
- ]);
1333
- }
1334
- }
1335
-
1336
- class VasReportModel extends VasJobDataModel {
1337
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job, reportLayout, title, sendEmail, message, attempted, completed, succeeded, attempts, notificationId) {
1338
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job);
1339
- this.id = id;
1340
- this.created = created;
1341
- this.serverCreated = serverCreated;
1342
- this.createdBy = createdBy;
1343
- this.modified = modified;
1344
- this.serverModified = serverModified;
1345
- this.modifiedBy = modifiedBy;
1346
- this.createdByName = createdByName;
1347
- this.modifiedByName = modifiedByName;
1348
- this.account = account;
1349
- this.job = job;
1350
- this.reportLayout = reportLayout;
1351
- this.title = title;
1352
- this.sendEmail = sendEmail;
1353
- this.message = message;
1354
- this.attempted = attempted;
1355
- this.completed = completed;
1356
- this.succeeded = succeeded;
1357
- this.attempts = attempts;
1358
- this.notificationId = notificationId;
1359
- }
1360
- static empty() {
1361
- return VasReportModel.fromDto({});
1362
- }
1363
- static fromDto(dto) {
1364
- return new VasReportModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.job || '', dto.reportLayout || '', dto.title || '', dto.sendEmail || '', dto.message || '', dto.attempted || '', dto.completed || '', dto.succeeded || '', dto.attempts || 0, dto.notificationId || '');
1365
- }
1366
- toDto() {
1367
- return {
1368
- id: this.id,
1369
- created: this.created,
1370
- serverCreated: this.serverCreated,
1371
- createdBy: this.createdBy,
1372
- modified: this.modified,
1373
- serverModified: this.serverModified,
1374
- modifiedBy: this.modifiedBy,
1375
- createdByName: this.createdByName,
1376
- modifiedByName: this.modifiedByName,
1377
- account: this.account,
1378
- job: this.job,
1379
- reportLayout: this.reportLayout,
1380
- title: this.title,
1381
- sendEmail: this.sendEmail,
1382
- message: this.message,
1383
- attempted: this.attempted,
1384
- completed: this.completed,
1385
- succeeded: this.succeeded,
1386
- attempts: this.attempts,
1387
- notificationId: this.notificationId,
1388
- };
1389
- }
1390
- toApiDto(options) {
1391
- return Object.assign(Object.assign({}, super.toApiDto(options)), { job: this.job, reportLayout: this.reportLayout });
1392
- }
1393
- static toApiPatchDto(item) {
1394
- return only(item, [
1395
- 'created',
1396
- 'modified',
1397
- 'portalVisible',
1398
- ]);
1399
- }
1400
- }
1401
-
1402
- /**
1403
- * VasNoteModel
1404
- */
1405
- class VasInstructionJobModel extends VasBaseModel {
1406
- /**
1407
- * @param id id
1408
- * @param created created
1409
- * @param serverCreated serverCreated
1410
- * @param createdBy createdBy
1411
- * @param modified modified
1412
- * @param serverModified serverModified
1413
- * @param modifiedBy modifiedBy
1414
- * @param reference reference
1415
- * @param jobStatus jobStatus
1416
- * @param createdByName createdByName
1417
- * @param modifiedByName modifiedByName
1418
- * @param notes notes
1419
- * @param fields fields
1420
- * @param files files
1421
- * @param reports reports
1422
- */
1423
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, reference, jobStatus, notes, fields, files, reports) {
1424
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName);
1425
- this.id = id;
1426
- this.created = created;
1427
- this.serverCreated = serverCreated;
1428
- this.createdBy = createdBy;
1429
- this.modified = modified;
1430
- this.serverModified = serverModified;
1431
- this.modifiedBy = modifiedBy;
1432
- this.createdByName = createdByName;
1433
- this.modifiedByName = modifiedByName;
1434
- this.reference = reference;
1435
- this.jobStatus = jobStatus;
1436
- this.notes = notes;
1437
- this.fields = fields;
1438
- this.files = files;
1439
- this.reports = reports;
1440
- }
1441
- /**
1442
- * @return empty VasInstructionJobModel
1443
- */
1444
- static empty() {
1445
- return new VasInstructionJobModel('', '', '', '', '', '', '', '', '', '', '', [], [], [], []);
1446
- }
1447
- /**
1448
- * @param dto VasInstructionDto
1449
- * @return VasInstructionModel
1450
- */
1451
- static fromDto(dto) {
1452
- return new VasInstructionJobModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.reference || '', dto.jobStatus || '', dto.createdByName || '', dto.modifiedByName || '', (dto.notes || []).map(d => VasNoteModel.fromDto(d)), (dto.fields || []).map(d => VasInstructionJobFieldModel.fromDto(d)), (dto.files || []).map(d => VasFileModel.fromDto(d)), (dto.reports || []).map(d => VasReportModel.fromDto(d)));
1453
- }
1454
- /**
1455
- * @returns VasNoteDto
1456
- */
1457
- toDto() {
1458
- return {
1459
- id: this.id,
1460
- created: this.created,
1461
- serverCreated: this.serverCreated,
1462
- createdBy: this.createdBy,
1463
- modified: this.modified,
1464
- serverModified: this.serverModified,
1465
- modifiedBy: this.modifiedBy,
1466
- reference: this.reference,
1467
- jobStatus: this.jobStatus,
1468
- createdByName: this.createdByName,
1469
- modifiedByName: this.modifiedByName,
1470
- notes: this.notes.map(m => m.toDto()),
1471
- fields: this.fields.map(m => m.toDto()),
1472
- files: this.files.map(m => m.toDto()),
1473
- reports: this.reports.map(m => m.toDto()),
1474
- };
1475
- }
1476
- }
1477
-
1478
- /**
1479
- * VasInstructionProviderModel
1480
- */
1481
- class VasInstructionProviderModel extends VasAccountObjectModel {
1482
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, form, title, secret, portalEnabled, portalVisible) {
1483
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account);
1484
- this.id = id;
1485
- this.created = created;
1486
- this.serverCreated = serverCreated;
1487
- this.createdBy = createdBy;
1488
- this.modified = modified;
1489
- this.serverModified = serverModified;
1490
- this.modifiedBy = modifiedBy;
1491
- this.createdByName = createdByName;
1492
- this.modifiedByName = modifiedByName;
1493
- this.account = account;
1494
- this.form = form;
1495
- this.title = title;
1496
- this.secret = secret;
1497
- this.portalEnabled = portalEnabled;
1498
- this.portalVisible = portalVisible;
1499
- }
1500
- /**
1501
- * @param dto VasInstructionDto
1502
- * @return VasInstructionModel
1503
- */
1504
- static fromDto(dto) {
1505
- return new VasInstructionProviderModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.form ?
1506
- VasFormModel.fromDto(dto.form) :
1507
- VasFormModel.empty(), dto.title || '', dto.secret || '', dto.portalEnabled || false, dto.portalVisible || true);
1508
- }
1509
- /**
1510
- * @returns VasNoteDto
1511
- */
1512
- toDto() {
1513
- return {
1514
- id: this.id,
1515
- created: this.created,
1516
- serverCreated: this.serverCreated,
1517
- createdBy: this.createdBy,
1518
- modified: this.modified,
1519
- serverModified: this.serverModified,
1520
- modifiedBy: this.modifiedBy,
1521
- createdByName: this.createdByName,
1522
- modifiedByName: this.modifiedByName,
1523
- account: this.account,
1524
- form: this.form.toDto(),
1525
- title: this.title,
1526
- secret: this.secret,
1527
- portalEnabled: this.portalEnabled,
1528
- portalVisible: this.portalVisible
1529
- };
1530
- }
1531
- toApiDto(options) {
1532
- return Object.assign(Object.assign({}, super.toApiDto(options)), { title: this.title, form: this.form.id, portalEnabled: this.portalEnabled, portalVisible: this.portalVisible });
1533
- }
1534
- }
1535
-
1536
- /**
1537
- * VasNoteModel
1538
- */
1539
- class VasInstructionModel extends VasAccountObjectModel {
1540
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job, instructionProvider) {
1541
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account);
1542
- this.id = id;
1543
- this.created = created;
1544
- this.serverCreated = serverCreated;
1545
- this.createdBy = createdBy;
1546
- this.modified = modified;
1547
- this.serverModified = serverModified;
1548
- this.modifiedBy = modifiedBy;
1549
- this.createdByName = createdByName;
1550
- this.modifiedByName = modifiedByName;
1551
- this.account = account;
1552
- this.job = job;
1553
- this.instructionProvider = instructionProvider;
1554
- }
1555
- /**
1556
- * @param dto VasInstructionDto
1557
- * @return VasInstructionModel
1558
- */
1559
- static fromDto(dto) {
1560
- return new VasInstructionModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.job ?
1561
- VasInstructionJobModel.fromDto(dto.job) :
1562
- VasInstructionJobModel.empty(), VasInstructionProviderModel.fromDto(dto.instructionProvider || {}));
1563
- }
1564
- /**
1565
- * @returns VasNoteDto
1566
- */
1567
- toDto() {
1568
- return {
1569
- id: this.id,
1570
- created: this.created,
1571
- serverCreated: this.serverCreated,
1572
- createdBy: this.createdBy,
1573
- modified: this.modified,
1574
- serverModified: this.serverModified,
1575
- modifiedBy: this.modifiedBy,
1576
- createdByName: this.createdByName,
1577
- modifiedByName: this.modifiedByName,
1578
- account: this.account,
1579
- job: this.job.toDto(),
1580
- instructionProvider: this.instructionProvider.toDto()
1581
- };
1582
- }
1583
- }
1584
-
1585
- var VasInvitationTypeEnum;
1586
- (function (VasInvitationTypeEnum) {
1587
- VasInvitationTypeEnum["TYPE_VAS_DESKTOP"] = "vas-desktop";
1588
- VasInvitationTypeEnum["TYPE_VAS_MOBILE"] = "vas-mobile";
1589
- VasInvitationTypeEnum["TYPE_VAS_PORTAL"] = "vas-portal";
1590
- VasInvitationTypeEnum["TYPE_P2C_DESKTOP"] = "p2c-desktop";
1591
- VasInvitationTypeEnum["TYPE_P2C_MOBILE"] = "p2c-mobile";
1592
- })(VasInvitationTypeEnum || (VasInvitationTypeEnum = {}));
1593
- class VasInvitationModel extends VasAccountObjectModel {
1594
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, secret, type, accessGroups, contactTypes, jobStatuses, jobTypes, lookupTypes, taskTypes, instructionProviders) {
1595
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account);
1596
- this.id = id;
1597
- this.created = created;
1598
- this.serverCreated = serverCreated;
1599
- this.createdBy = createdBy;
1600
- this.modified = modified;
1601
- this.serverModified = serverModified;
1602
- this.modifiedBy = modifiedBy;
1603
- this.createdByName = createdByName;
1604
- this.modifiedByName = modifiedByName;
1605
- this.account = account;
1606
- this.secret = secret;
1607
- this.type = type;
1608
- this.accessGroups = accessGroups;
1609
- this.contactTypes = contactTypes;
1610
- this.jobStatuses = jobStatuses;
1611
- this.jobTypes = jobTypes;
1612
- this.lookupTypes = lookupTypes;
1613
- this.taskTypes = taskTypes;
1614
- this.instructionProviders = instructionProviders;
1615
- }
1616
- toDto() {
1617
- return {
1618
- id: this.id,
1619
- created: this.created,
1620
- serverCreated: this.serverCreated,
1621
- createdBy: this.createdBy,
1622
- modified: this.modified,
1623
- serverModified: this.serverModified,
1624
- modifiedBy: this.modifiedBy,
1625
- createdByName: this.createdByName,
1626
- modifiedByName: this.modifiedByName,
1627
- account: this.account,
1628
- secret: this.secret,
1629
- type: this.type,
1630
- accessGroups: this.accessGroups,
1631
- contactTypes: this.contactTypes,
1632
- jobStatuses: this.jobStatuses,
1633
- jobTypes: this.jobTypes,
1634
- lookupTypes: this.lookupTypes,
1635
- taskTypes: this.taskTypes,
1636
- instructionProviders: this.instructionProviders,
1637
- };
1638
- }
1639
- static fromDto(dto) {
1640
- return new VasInvitationModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.secret || '', dto.type || VasInvitationTypeEnum.TYPE_VAS_PORTAL, dto.accessGroups || [], dto.contactTypes || [], dto.jobStatuses || [], dto.jobTypes || [], dto.lookupTypes || [], dto.taskTypes || [], dto.instructionProviders || []);
1641
- }
1642
- toApiDto(options) {
1643
- const dto = Object.assign(Object.assign({}, super.toApiDto()), { type: this.type });
1644
- if (this.accessGroups.length) {
1645
- dto['accessGroups'] = this.accessGroups.map(d => d.id);
1646
- }
1647
- if (this.contactTypes.length) {
1648
- dto['contactTypes'] = this.contactTypes.map(d => d.id);
1649
- }
1650
- if (this.jobStatuses.length) {
1651
- dto['jobStatuses'] = this.jobStatuses.map(d => d.id);
1652
- }
1653
- if (this.jobTypes.length) {
1654
- dto['jobTypes'] = this.jobTypes.map(d => d.id);
1655
- }
1656
- if (this.lookupTypes.length) {
1657
- dto['lookupTypes'] = this.lookupTypes.map(d => d.id);
1658
- }
1659
- if (this.taskTypes.length) {
1660
- dto['taskTypes'] = this.taskTypes.map(d => d.id);
1661
- }
1662
- if (this.instructionProviders.length) {
1663
- dto['instructionProviders'] = this.instructionProviders.map(d => d.id);
1664
- }
1665
- return dto;
1666
- }
1667
- }
1668
-
1669
- const isJobAutomationStep = (step) => {
1670
- return step && step.type === 'automation';
1671
- };
1672
- const isJobControlsStep = (step) => {
1673
- return step && step.type === 'controls';
1674
- };
1675
- const isJobEmailFormStep = (step) => {
1676
- return step && step.type === 'email-form';
1677
- };
1678
- const isJobNotePromptStep = (step) => {
1679
- return step && step.type === 'note-prompt';
1680
- };
1681
- const isJobSetDatetimeStep = (step) => {
1682
- return step && step.type === 'set-datetime';
1683
- };
1684
- const isJobSetJobStatusStep = (step) => {
1685
- return step && step.type === 'set-job-status';
1686
- };
1687
- const isJobSetValueStep = (step) => {
1688
- return step && step.type === 'set-value';
1689
- };
1690
-
1691
- class VasJobCopyModel {
1692
- constructor(accessGroup, jobType, jobStatus, jobDate, assigneeId, fields, files, reports) {
1693
- this.accessGroup = accessGroup;
1694
- this.jobType = jobType;
1695
- this.jobStatus = jobStatus;
1696
- this.jobDate = jobDate;
1697
- this.assigneeId = assigneeId;
1698
- this.fields = fields;
1699
- this.files = files;
1700
- this.reports = reports;
1701
- }
1702
- static fromDto(dto) {
1703
- return new VasJobCopyModel(dto.accessGroup || '', dto.jobType || '', dto.jobStatus || '', dto.jobDate || '', dto.assigneeId || '', dto.fields || [], dto.files || [], dto.reports || []);
1704
- }
1705
- toDto() {
1706
- return {
1707
- accessGroup: this.accessGroup,
1708
- jobType: this.jobType,
1709
- jobStatus: this.jobStatus,
1710
- jobDate: this.jobDate,
1711
- assigneeId: this.assigneeId,
1712
- fields: this.fields,
1713
- files: this.files,
1714
- reports: this.reports,
1715
- };
1716
- }
1717
- toApiDto() {
1718
- return {
1719
- jobType: this.jobType,
1720
- jobStatus: this.jobStatus,
1721
- jobDate: this.jobDate,
1722
- assigneeId: this.assigneeId,
1723
- fields: this.fields,
1724
- files: this.files,
1725
- reports: this.reports,
1726
- };
1727
- }
1728
- }
1729
-
1730
- class VasJobEmailModel extends VasJobDataModel {
1731
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job, body, cc, files, message, recipients, replyTo, reports, sender, sentTime, subject, succeeded) {
1732
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job);
1733
- this.id = id;
1734
- this.created = created;
1735
- this.serverCreated = serverCreated;
1736
- this.createdBy = createdBy;
1737
- this.modified = modified;
1738
- this.serverModified = serverModified;
1739
- this.modifiedBy = modifiedBy;
1740
- this.createdByName = createdByName;
1741
- this.modifiedByName = modifiedByName;
1742
- this.account = account;
1743
- this.job = job;
1744
- this.body = body;
1745
- this.cc = cc;
1746
- this.files = files;
1747
- this.message = message;
1748
- this.recipients = recipients;
1749
- this.replyTo = replyTo;
1750
- this.reports = reports;
1751
- this.sender = sender;
1752
- this.sentTime = sentTime;
1753
- this.subject = subject;
1754
- this.succeeded = succeeded;
1755
- }
1756
- static fromDto(dto) {
1757
- return new VasJobEmailModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.job || '', dto.body || '', dto.cc || [], dto.files || [], dto.message || '', dto.recipients || [], dto.replyTo || '', dto.reports || [], dto.sender || '', dto.sentTime || '', dto.subject || '', dto.succeeded || false);
1758
- }
1759
- toDto() {
1760
- return {
1761
- id: this.id,
1762
- created: this.created,
1763
- serverCreated: this.serverCreated,
1764
- createdBy: this.createdBy,
1765
- modified: this.modified,
1766
- serverModified: this.serverModified,
1767
- modifiedBy: this.modifiedBy,
1768
- createdByName: this.createdByName,
1769
- modifiedByName: this.modifiedByName,
1770
- account: this.account,
1771
- job: this.job,
1772
- body: this.body,
1773
- cc: this.cc,
1774
- files: this.files,
1775
- message: this.message,
1776
- recipients: this.recipients,
1777
- replyTo: this.replyTo,
1778
- reports: this.reports,
1779
- sender: this.sender,
1780
- sentTime: this.sentTime,
1781
- subject: this.subject,
1782
- succeeded: this.succeeded,
1783
- };
1784
- }
1785
- toApiDto(options) {
1786
- return {
1787
- // id: this.id,
1788
- created: this.created,
1789
- modified: this.modified,
1790
- body: this.body,
1791
- cc: this.cc,
1792
- files: this.files,
1793
- recipients: this.recipients,
1794
- reports: this.reports,
1795
- subject: this.subject,
1796
- };
1797
- }
1798
- static toApiPatchDto(item) {
1799
- return only(item, [
1800
- 'created',
1801
- 'modified',
1802
- 'body',
1803
- 'cc',
1804
- 'files',
1805
- 'message',
1806
- 'recipients',
1807
- 'reports',
1808
- 'subject',
1809
- ]);
1810
- }
1811
- }
1812
-
1813
- /**
1814
- * A non sophisticated way to get values from the job via paths. For example:
1815
- *
1816
- * getValueByPath(
1817
- * ['foo', 'bar'],
1818
- * {
1819
- * foo: {
1820
- * bar: 'value'
1821
- * }
1822
- * }
1823
- * );
1824
- *
1825
- * will return "value"
1826
- * @param {string[]} path
1827
- * @param {Record<string, VasFieldDtoValue>} object
1828
- * @return {T | undefined}
1829
- */
1830
- const getValueByPath = (path, object) => {
1831
- switch (path.length) {
1832
- case 0: {
1833
- return;
1834
- }
1835
- case 1: {
1836
- return (object)[path[0]];
1837
- }
1838
- case 2: {
1839
- const val0 = object[path[0]];
1840
- if (!val0) {
1841
- return undefined;
1842
- }
1843
- return val0[path[1]];
1844
- }
1845
- case 3: {
1846
- const val0 = object[path[0]];
1847
- if (!val0) {
1848
- return undefined;
1849
- }
1850
- const val1 = val0[path[1]];
1851
- if (!val1) {
1852
- return undefined;
1853
- }
1854
- return val1[path[2]];
1855
- }
1856
- case 4: {
1857
- const val0 = object[path[0]];
1858
- if (!val0) {
1859
- return undefined;
1860
- }
1861
- const val1 = val0[path[1]];
1862
- if (!val1) {
1863
- return undefined;
1864
- }
1865
- const val2 = val1[path[2]];
1866
- if (!val2) {
1867
- return undefined;
1868
- }
1869
- return val2[path[3]];
1870
- }
1871
- default: {
1872
- throw Error('path has too many segments');
1873
- }
1874
- }
1875
- };
1876
-
1877
- const getEmptyGeoLocation = () => ({
1878
- accuracy: 0,
1879
- altitude: 0,
1880
- altitudeAccuracy: 0,
1881
- geoPoint: [],
1882
- lonLat: {
1883
- lon: 0,
1884
- lat: 0,
1885
- },
1886
- timestamp: ''
1887
- });
1888
-
1889
- const isArrayString = (value) => {
1890
- return Array.isArray(value) && value.every(i => typeof i === 'string');
1891
- };
1892
-
1893
- /**
1894
- * JobModel
1895
- */
1896
- class VasJobModel extends VasRestrictedAccountObjectModel {
1897
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, reference, jobDate, jobStatus, jobType, assigneeId, formId, timeZoneOffset, pendingFields, childModified, version, createdByDisplayName, modifiedByDisplayName, geoLocation, files, fields, jobEmails, notes, reports, tasks, instruction) {
1898
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
1899
- this.id = id;
1900
- this.created = created;
1901
- this.serverCreated = serverCreated;
1902
- this.createdBy = createdBy;
1903
- this.modified = modified;
1904
- this.serverModified = serverModified;
1905
- this.modifiedBy = modifiedBy;
1906
- this.createdByName = createdByName;
1907
- this.modifiedByName = modifiedByName;
1908
- this.account = account;
1909
- this.accessGroup = accessGroup;
1910
- this.reference = reference;
1911
- this.jobDate = jobDate;
1912
- this.jobStatus = jobStatus;
1913
- this.jobType = jobType;
1914
- this.assigneeId = assigneeId;
1915
- this.formId = formId;
1916
- this.timeZoneOffset = timeZoneOffset;
1917
- this.pendingFields = pendingFields;
1918
- this.childModified = childModified;
1919
- this.version = version;
1920
- this.createdByDisplayName = createdByDisplayName;
1921
- this.modifiedByDisplayName = modifiedByDisplayName;
1922
- this.geoLocation = geoLocation;
1923
- this.files = files;
1924
- this.fields = fields;
1925
- this.jobEmails = jobEmails;
1926
- this.notes = notes;
1927
- this.reports = reports;
1928
- this.tasks = tasks;
1929
- this.instruction = instruction;
1930
- }
1931
- /**
1932
- * Returns this with the dynamic interface
1933
- * @return {VasJobModelDynamicInterface}
1934
- */
1935
- get $this() {
1936
- return this;
1937
- }
1938
- /**
1939
- * Returns a list of Job dynamic properties i.e. those that are added by the
1940
- * dynamic forms
1941
- */
1942
- get dynamicProperties() {
1943
- const nativeProps = this.staticProperties;
1944
- return Object
1945
- .getOwnPropertyNames(this)
1946
- .filter(prop => !nativeProps.includes(prop));
1947
- }
1948
- /**
1949
- * Returns the list of properties of the Job type
1950
- */
1951
- get staticProperties() {
1952
- return Object.getOwnPropertyNames(VasJobModel.empty());
1953
- }
1954
- /**
1955
- * @return {VasJobModel}
1956
- */
1957
- static empty() {
1958
- return new VasJobModel('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', moment().utcOffset(), 0, '', 0, '', '', getEmptyGeoLocation(), [], [], [], [], [], [], null);
1959
- }
1960
- static fromDto(dto) {
1961
- const model = new VasJobModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', dto.reference || '', dto.jobDate || '', dto.jobStatus || '', dto.jobType || '', dto.assigneeId || '', dto.formId || dto.lastForm || '', dto.timeZoneOffset || moment().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.createdByDisplayName || '', dto.modifiedByDisplayName || '', dto.geoLocation || getEmptyGeoLocation(), dto.files || [], dto.fields || [], dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
1962
- const emptyKeys = model.staticProperties;
1963
- Object
1964
- .keys(dto)
1965
- .filter(key => emptyKeys.indexOf(key) === -1)
1966
- .forEach((key) => model.$this[key] = dto[key]);
1967
- return model;
1968
- }
1969
- /**
1970
- * This method will instantiate a new JobModel. The difference with this
1971
- * method of instantiation is that we are coming from a relation frame i.e.
1972
- * the job has a list of {@link VasFieldDto} instead of a Job document.
1973
- *
1974
- */
1975
- static fromRelational(dto, form) {
1976
- const model = new VasJobModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', dto.reference || '', dto.jobDate || '', dto.jobStatus || '', dto.jobType || '', dto.assigneeId || '', dto.formId || '', dto.timeZoneOffset || moment().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.createdByDisplayName || '', dto.modifiedByDisplayName || '', dto.geoLocation || getEmptyGeoLocation(), dto.files || [], dto.fields || [], dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
1977
- form.groups
1978
- .forEach(group => {
1979
- group.controls
1980
- .forEach(control => {
1981
- var _a;
1982
- const field = (_a = dto.fields) === null || _a === void 0 ? void 0 : _a.find(f => f.control === control.id);
1983
- if (!field) {
1984
- return;
1985
- }
1986
- model.getGroup(group.name)[control.name] = field.value;
1987
- });
1988
- });
1989
- return model;
1990
- }
1991
- /**
1992
- * @param {VasFormModel} formModel
1993
- * @return {Record<string, VasFieldDtoValue>}
1994
- */
1995
- getFields(formModel) {
1996
- const fields = {};
1997
- formModel.groups
1998
- .forEach(group => {
1999
- group.controls.forEach(control => {
2000
- (fields)[control.reportTemplateName] =
2001
- this.getValueByPath([group.name, control.name]) || null;
2002
- });
2003
- });
2004
- return fields;
2005
- }
2006
- /**
2007
- * Will return an object whose keys are the names of all fields in the job.
2008
- * This method is similar to `getFields` except that this method will only
2009
- * return values where a value was set, as opposed to `getFields` which will
2010
- * return a value for every control even if no value was set, because it uses
2011
- * the form to drive the logic. Note also this method will return values for
2012
- * any Fields in the fields array.
2013
- * @return {Record<string, VasFieldDtoValue>}
2014
- */
2015
- getFields2() {
2016
- let fields = {};
2017
- this.dynamicProperties
2018
- .forEach((groupName) => {
2019
- Object
2020
- .keys(this.$this[groupName])
2021
- .forEach(controlName => {
2022
- fields[controlName] =
2023
- this.getValueByPath([groupName, controlName]) || null;
2024
- });
2025
- }, {});
2026
- this.fields.forEach(field => fields[field.controlName] = field.value);
2027
- return fields;
2028
- }
2029
- /**
2030
- * Returns an object describing how many attachments were added to this job
2031
- * (camera controls and files), and how many have not been uploaded yet.
2032
- *
2033
- * @param formModel instance of {@link VasFormModel} that was used when the
2034
- * job was created
2035
- */
2036
- getFilesUploadStatus(formModel) {
2037
- const pathsWithValue = formModel
2038
- .getCameraControlPaths()
2039
- .map(path => {
2040
- const value = this.getValueByPath(path);
2041
- if (value && !!value.id) {
2042
- return path;
2043
- }
2044
- return null;
2045
- })
2046
- .filter(path => path !== null ? path : null)
2047
- .filter(isArrayString);
2048
- let total = pathsWithValue.length;
2049
- total += this.files.length;
2050
- // calculate the number of camera images still to upload
2051
- let pending = pathsWithValue
2052
- .map(path => this.getValueByPath(path))
2053
- .map((value) => {
2054
- if (isFileDto(value)) {
2055
- return value.id && value.status !== 'COMPLETE';
2056
- }
2057
- else if (isCameraControlValueV1(value)) {
2058
- // if url is not set, it hasn't been uploaded
2059
- return value.id && !value.url;
2060
- }
2061
- return false;
2062
- })
2063
- .filter(hasUploaded => hasUploaded)
2064
- .length;
2065
- // add total from files that are pending
2066
- pending += this.files
2067
- .filter(value => value.status !== 'COMPLETE')
2068
- .length;
2069
- return {
2070
- pending,
2071
- total
2072
- };
2073
- }
2074
- /**
2075
- * This method will return the dynamic property from the JobModel that
2076
- * represent a group (from a form).
2077
- *
2078
- * @param name the name of the group
2079
- * @param init if true (default) and group is not found, initialise an empty
2080
- * group, otherwise throw an error
2081
- */
2082
- getGroup(name, init = true) {
2083
- let prop;
2084
- if (this.staticProperties.includes(name)) {
2085
- throw Error(`invalid group name ${name}, not a dynamic property`);
2086
- }
2087
- else if (this.$this[name] === undefined) {
2088
- if (init) {
2089
- prop = this.$this[name] = {};
2090
- }
2091
- else {
2092
- throw Error(`invalid group name ${name}, not found`);
2093
- }
2094
- }
2095
- else {
2096
- prop = this.$this[name];
2097
- if (typeof prop !== 'object') {
2098
- throw Error(`invalid group name ${name}, not an object`);
2099
- }
2100
- }
2101
- return prop;
2102
- }
2103
- /**
2104
- * @param path path segments
2105
- */
2106
- getValueByPath(path = []) {
2107
- return getValueByPath(path, this.$this);
2108
- }
2109
- /**
2110
- * In order to understand why we need this method it is important to
2111
- * understand that within the system, Jobs can be represented in one of two
2112
- * ways, document and relational.
2113
- *
2114
- * The important distinction is how values submitted by a form are stored.
2115
- *
2116
- * Jobs stored as documents (JSON objects) will store user values, as dynamic
2117
- * properties of the document.
2118
- *
2119
- * Whereas, Jobs stored as relational, will store user values in an array of
2120
- * {@link VasFieldDto} objects.
2121
- *
2122
- * Depending on where we are in the system, either one of these approaches can
2123
- * be more useful than the other.
2124
- *
2125
- * This method, assumes that the JobModel has been instantiated from a
2126
- * document representation, and serves to hydrate the fields array. In order
2127
- * to achieve this, knowledge of the {@link VasFormDto} that created the job
2128
- * is required.
2129
- *
2130
- *
2131
- * Job in document representation
2132
- * {
2133
- * id: <guid>,
2134
- * reference: "something"
2135
- * <other static job properties>...
2136
- * foo: {
2137
- * bar: "value"
2138
- * }
2139
- * }
2140
- *
2141
- * Job in relational representation
2142
- * {
2143
- * id: <guid>,
2144
- * reference: "something"
2145
- * <other static job properties>...
2146
- * <will not have dynamic properties>...
2147
- * fields: [
2148
- * {
2149
- * id: <guid>,
2150
- * <other field properties>,
2151
- * value: "value"
2152
- * }
2153
- * ]
2154
- * }
2155
- *
2156
- *
2157
- * @param formModel the VasFormModel that was used to create the job
2158
- * @param controlFieldIdMap This is used to determine the id each field.
2159
- * Either one will be found in the map, or a new one is generated.
2160
- * @param controlNames if a value is provided, it will be used
2161
- * to filter the fields that are returned.
2162
- * @return {Array<VasFieldDto>}
2163
- */
2164
- hydrateFields(formModel, controlFieldIdMap = new Map(), controlNames) {
2165
- const fields = [];
2166
- formModel.groups
2167
- .forEach(group => {
2168
- group.controls.forEach(control => {
2169
- if (!control.name.startsWith('fields.')) {
2170
- return;
2171
- }
2172
- if (controlNames && !controlNames.includes(control.name)) {
2173
- return;
2174
- }
2175
- fields.push(VasFieldModel.fromDto({
2176
- // if the controlId exists in the map, use the associated fieldId,
2177
- // otherwise generate a new id for the field.
2178
- id: controlFieldIdMap.get(control.id) || UUID.UUID(),
2179
- account: this.account,
2180
- job: this.id,
2181
- createdBy: this.createdBy,
2182
- created: this.created,
2183
- modifiedBy: this.modifiedBy,
2184
- modified: this.modified,
2185
- control: control.id,
2186
- value: this.getValueByPath([group.name, control.name])
2187
- }));
2188
- });
2189
- });
2190
- this.fields = fields;
2191
- }
2192
- /**
2193
- * A very non sophisticated way to set values in the job via paths
2194
- *
2195
- * For example:
2196
- *
2197
- * setValueByPath('value', ['foo', 'bar']);
2198
- *
2199
- * will make results in job
2200
- * {
2201
- * foo: {
2202
- * bar: 'value'
2203
- * }
2204
- * }
2205
- *
2206
- * @param value the value to set
2207
- * @param path path segments
2208
- */
2209
- setValueByPath(value, path = []) {
2210
- switch (path.length) {
2211
- case 0: {
2212
- return;
2213
- }
2214
- case 1: {
2215
- this[path[0]] = value;
2216
- return;
2217
- }
2218
- case 2: {
2219
- // eslint-disable-next-line max-len
2220
- this.$this[path[0]][path[1]] = value;
2221
- return;
2222
- }
2223
- case 3: {
2224
- // eslint-disable-next-line max-len
2225
- this.$this[path[0]][path[1]][path[2]] = value;
2226
- return;
2227
- }
2228
- default: {
2229
- throw Error('path has too many segments');
2230
- }
2231
- }
2232
- }
2233
- /**
2234
- * @param staticOnly if true, will only output values for the static
2235
- * properties in the dto
2236
- */
2237
- toDto(staticOnly = false) {
2238
- if (staticOnly) {
2239
- return {
2240
- id: this.id,
2241
- created: this.created,
2242
- createdBy: this.createdBy,
2243
- modified: this.modified,
2244
- modifiedBy: this.modifiedBy,
2245
- serverCreated: this.serverCreated,
2246
- serverModified: this.serverModified,
2247
- createdByName: this.createdByName,
2248
- modifiedByName: this.modifiedByName,
2249
- account: this.account,
2250
- accessGroup: this.accessGroup,
2251
- reference: this.reference,
2252
- jobDate: this.jobDate,
2253
- jobStatus: this.jobStatus,
2254
- jobType: this.jobType,
2255
- assigneeId: this.assigneeId,
2256
- formId: this.formId,
2257
- timeZoneOffset: this.timeZoneOffset,
2258
- pendingFields: this.pendingFields,
2259
- childModified: this.childModified,
2260
- version: this.version,
2261
- createdByDisplayName: this.createdByDisplayName,
2262
- modifiedByDisplayName: this.modifiedByDisplayName,
2263
- geoLocation: this.geoLocation,
2264
- files: this.files,
2265
- fields: this.fields,
2266
- jobEmails: this.jobEmails,
2267
- notes: this.notes,
2268
- reports: this.reports,
2269
- tasks: this.tasks,
2270
- instruction: this.instruction
2271
- };
2272
- }
2273
- const dto = {};
2274
- [...this.staticProperties, ...this.dynamicProperties]
2275
- .forEach(prop => dto[prop] = this.$this[prop]);
2276
- return dto;
2277
- }
2278
- /**
2279
- * This method will parse a syntax that allows us to build strings from the
2280
- * values of from the job model. For example if the job model was:
2281
- *
2282
- * {
2283
- * foo: 'bar'
2284
- * }
2285
- *
2286
- * and we pass "i am foo {foo}", the result would be:
2287
- *
2288
- * "i am foo bar"
2289
- *
2290
- * we can also use moment to parse dates, for example if the job model was:
2291
- *
2292
- * {
2293
- * created: "2022-01-01T00:00:00+0000"
2294
- * }
2295
- *
2296
- * and we pass "{created|date:YY-MM-DD}", the result would be:
2297
- *
2298
- * "2022-01-01"
2299
- *
2300
- * @param {string} value a string with the syntax
2301
- * @param {ParseSyntaxOptions} options
2302
- * @return the results of parsing the syntax on this job
2303
- */
2304
- parseSyntax(value, options = {
2305
- timeZoneOffset: 0
2306
- }) {
2307
- if (!value || typeof value !== 'string') {
2308
- return '';
2309
- }
2310
- const fields = this.getFields2();
2311
- return value.replace(/({[^}]*})/g, (match, token) => {
2312
- const syntax = token.substring(1, token.length - 1);
2313
- let [key, filter] = syntax.split('|');
2314
- key = (key || '').trim();
2315
- filter = (filter || '').trim();
2316
- let filterName, filterArg = '';
2317
- if (filter) {
2318
- const splitIndex = filter.indexOf(':');
2319
- if (splitIndex !== -1) {
2320
- filterName = filter.substring(0, splitIndex);
2321
- filterArg = filter.substring(splitIndex + 1);
2322
- }
2323
- else {
2324
- filterName = filter;
2325
- filterArg = '';
2326
- }
2327
- filterName = (filterName || '').trim();
2328
- filterArg = (filterArg || '').trim();
2329
- }
2330
- const path = key.split('.');
2331
- const objectKey = path.shift() || '';
2332
- let result = '';
2333
- if (objectKey === 'job') {
2334
- result = (this.getValueByPath(path) || '').toString();
2335
- }
2336
- else if (objectKey === 'fields') {
2337
- result = (getValueByPath(['fields.' + path.shift(), ...path], fields) || '').toString();
2338
- }
2339
- else if (objectKey.length) {
2340
- if (options.objects) {
2341
- if (options.objects[objectKey] === undefined) {
2342
- console.debug(`objectKey ${objectKey} is not present in options.object`);
2343
- result = '';
2344
- }
2345
- else {
2346
- result = (getValueByPath(path, options.objects[objectKey]) || '')
2347
- .toString();
2348
- }
2349
- }
2350
- else {
2351
- console.debug(`objectKey ${objectKey} was used but options.object is not set`);
2352
- return '';
2353
- }
2354
- }
2355
- else {
2356
- return '';
2357
- }
2358
- if (filterName && result) {
2359
- switch (filterName) {
2360
- case 'date': {
2361
- if (!options.timeZoneOffset) {
2362
- return moment(result).format(filterArg || '');
2363
- }
2364
- else {
2365
- return moment(result)
2366
- .utcOffset(options.timeZoneOffset)
2367
- .format(filterArg || '');
2368
- }
2369
- }
2370
- default: {
2371
- console.warn('unknown filter %s', filterName);
2372
- }
2373
- }
2374
- }
2375
- return result;
2376
- }).trim();
2377
- }
2378
- ;
2379
- /**
2380
- * @return {object}
2381
- */
2382
- toApiDto() {
2383
- return Object.assign(Object.assign({}, super.toApiDto()), { reference: this.reference || '~', jobDate: this.jobDate || '~', jobType: this.jobType || '~', accessGroup: this.accessGroup || '~', jobStatus: this.jobStatus || '~', assigneeId: this.assigneeId || '~', timeZoneOffset: this.timeZoneOffset || 0, pendingFields: this.pendingFields || 0, lastForm: this.formId || '~' });
2384
- }
2385
- static toApiPatchDto(item) {
2386
- return only(item, [
2387
- 'created',
2388
- 'modified',
2389
- 'reference',
2390
- 'jobDate',
2391
- 'jobType',
2392
- 'accessGroup',
2393
- 'jobStatus',
2394
- 'assigneeId',
2395
- 'timeZoneOffset',
2396
- 'pendingFields',
2397
- 'lastForm'
2398
- ]);
2399
- }
2400
- }
2401
-
2402
- /**
2403
- * VasLookupModel
2404
- */
2405
- class VasLookupModel extends VasRestrictedAccountObjectModel {
2406
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, content, lookupType, sequence, title) {
2407
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
2408
- this.id = id;
2409
- this.created = created;
2410
- this.serverCreated = serverCreated;
2411
- this.createdBy = createdBy;
2412
- this.modified = modified;
2413
- this.serverModified = serverModified;
2414
- this.modifiedBy = modifiedBy;
2415
- this.createdByName = createdByName;
2416
- this.modifiedByName = modifiedByName;
2417
- this.account = account;
2418
- this.accessGroup = accessGroup;
2419
- this.content = content;
2420
- this.lookupType = lookupType;
2421
- this.sequence = sequence;
2422
- this.title = title;
2423
- }
2424
- /**
2425
- * @param dto VasLookupDto
2426
- * @return VasLookupModel
2427
- */
2428
- static fromDto(dto) {
2429
- return new VasLookupModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.accessGroup || '', dto.content || '', dto.lookupType || '', dto.sequence || 0, dto.title || '');
2430
- }
2431
- /**
2432
- * @returns VasLookupDto
2433
- */
2434
- toDto() {
2435
- return {
2436
- id: this.id,
2437
- created: this.created,
2438
- serverCreated: this.serverCreated,
2439
- createdBy: this.createdBy,
2440
- modified: this.modified,
2441
- serverModified: this.serverModified,
2442
- modifiedBy: this.modifiedBy,
2443
- createdByName: this.createdByName,
2444
- modifiedByName: this.modifiedByName,
2445
- account: this.account,
2446
- accessGroup: this.accessGroup,
2447
- content: this.content,
2448
- lookupType: this.lookupType,
2449
- sequence: this.sequence,
2450
- title: this.title,
2451
- };
2452
- }
2453
- toApiDto(options) {
2454
- return Object.assign(Object.assign({}, super.toApiDto(options)), { content: this.content || '', lookupType: this.lookupType || '~', sequence: Number.isSafeInteger(this.sequence) || 0, title: this.title || '' });
2455
- }
2456
- static toApiPatchDto(item) {
2457
- return only(item, [
2458
- 'created',
2459
- 'modified',
2460
- 'accessGroup',
2461
- 'lookupType',
2462
- 'title',
2463
- 'content',
2464
- 'sequence'
2465
- ]);
2466
- }
2467
- }
2468
-
2469
- /**
2470
- * VasMembershipModel
2471
- */
2472
- class VasMembershipModel extends VasAccountObjectModel {
2473
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, user, admin, lookupTypes, contactTypes, accessGroups, jobStatuses, jobTypes, taskTypes) {
2474
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account);
2475
- this.id = id;
2476
- this.created = created;
2477
- this.serverCreated = serverCreated;
2478
- this.createdBy = createdBy;
2479
- this.modified = modified;
2480
- this.serverModified = serverModified;
2481
- this.modifiedBy = modifiedBy;
2482
- this.createdByName = createdByName;
2483
- this.modifiedByName = modifiedByName;
2484
- this.account = account;
2485
- this.user = user;
2486
- this.admin = admin;
2487
- this.lookupTypes = lookupTypes;
2488
- this.contactTypes = contactTypes;
2489
- this.accessGroups = accessGroups;
2490
- this.jobStatuses = jobStatuses;
2491
- this.jobTypes = jobTypes;
2492
- this.taskTypes = taskTypes;
2493
- }
2494
- static empty() {
2495
- return VasMembershipModel.fromDto({
2496
- // eslint-disable-next-line new-cap
2497
- id: UUID.UUID()
2498
- });
2499
- }
2500
- static fromDto(dto) {
2501
- return new VasMembershipModel(
2502
- // eslint-disable-next-line new-cap
2503
- dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.user || '', dto.admin || false, dto.lookupTypes || [], dto.contactTypes || [], dto.accessGroups || [], dto.jobStatuses || [], dto.jobTypes || [], dto.taskTypes || []);
2504
- }
2505
- toDto() {
2506
- return {
2507
- id: this.id,
2508
- created: this.created,
2509
- serverCreated: this.serverCreated,
2510
- createdBy: this.createdBy,
2511
- modified: this.modified,
2512
- serverModified: this.serverModified,
2513
- modifiedBy: this.modifiedBy,
2514
- createdByName: this.createdByName,
2515
- modifiedByName: this.modifiedByName,
2516
- account: this.account,
2517
- user: this.user,
2518
- admin: this.admin,
2519
- lookupTypes: this.lookupTypes,
2520
- contactTypes: this.contactTypes,
2521
- accessGroups: this.accessGroups,
2522
- jobStatuses: this.jobStatuses,
2523
- jobTypes: this.jobTypes,
2524
- taskTypes: this.taskTypes
2525
- };
2526
- }
2527
- }
2528
-
2529
- class VasReportLayoutModel extends VasRestrictedAccountObjectModel {
2530
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, jobType, title, description, entryPoint) {
2531
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
2532
- this.id = id;
2533
- this.created = created;
2534
- this.serverCreated = serverCreated;
2535
- this.createdBy = createdBy;
2536
- this.modified = modified;
2537
- this.serverModified = serverModified;
2538
- this.modifiedBy = modifiedBy;
2539
- this.createdByName = createdByName;
2540
- this.modifiedByName = modifiedByName;
2541
- this.account = account;
2542
- this.accessGroup = accessGroup;
2543
- this.jobType = jobType;
2544
- this.title = title;
2545
- this.description = description;
2546
- this.entryPoint = entryPoint;
2547
- }
2548
- }
2549
-
2550
- class VasReportRequestModel extends VasAccountObjectModel {
2551
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, error, jobId, title, url, reportId) {
2552
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account);
2553
- this.id = id;
2554
- this.created = created;
2555
- this.serverCreated = serverCreated;
2556
- this.createdBy = createdBy;
2557
- this.modified = modified;
2558
- this.serverModified = serverModified;
2559
- this.modifiedBy = modifiedBy;
2560
- this.createdByName = createdByName;
2561
- this.modifiedByName = modifiedByName;
2562
- this.account = account;
2563
- this.error = error;
2564
- this.jobId = jobId;
2565
- this.title = title;
2566
- this.url = url;
2567
- this.reportId = reportId;
2568
- }
2569
- static fromDto(dto) {
2570
- return new VasReportRequestModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.error || '', dto.jobId || '', dto.title || '', dto.url || '', dto.reportId || '');
2571
- }
2572
- toDto() {
2573
- return {
2574
- id: this.id,
2575
- created: this.created,
2576
- serverCreated: this.serverCreated,
2577
- createdBy: this.createdBy,
2578
- modified: this.modified,
2579
- serverModified: this.serverModified,
2580
- modifiedBy: this.modifiedBy,
2581
- createdByName: this.createdByName,
2582
- modifiedByName: this.modifiedByName,
2583
- account: this.account,
2584
- error: this.error,
2585
- jobId: this.jobId,
2586
- title: this.title,
2587
- url: this.url,
2588
- reportId: this.reportId
2589
- };
2590
- }
2591
- }
2592
-
2593
- /**
2594
- * VasTaskModel
2595
- */
2596
- class VasTaskModel extends VasJobDataModel {
2597
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job, assignee, done, dueDate, taskType, title, jobReference) {
2598
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, job);
2599
- this.id = id;
2600
- this.created = created;
2601
- this.serverCreated = serverCreated;
2602
- this.createdBy = createdBy;
2603
- this.modified = modified;
2604
- this.serverModified = serverModified;
2605
- this.modifiedBy = modifiedBy;
2606
- this.createdByName = createdByName;
2607
- this.modifiedByName = modifiedByName;
2608
- this.account = account;
2609
- this.job = job;
2610
- this.assignee = assignee;
2611
- this.done = done;
2612
- this.dueDate = dueDate;
2613
- this.taskType = taskType;
2614
- this.title = title;
2615
- this.jobReference = jobReference;
2616
- }
2617
- /**
2618
- * @param dto VasTaskDto
2619
- * @return VasNoteModel
2620
- */
2621
- static fromDto(dto) {
2622
- return new VasTaskModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.job || '', dto.assignee || '', dto.done || false, dto.dueDate || '', dto.taskType || '', dto.title || '', dto.jobReference || '');
2623
- }
2624
- /**
2625
- * @returns VasTaskDto
2626
- */
2627
- toDto() {
2628
- return {
2629
- id: this.id,
2630
- created: this.created,
2631
- serverCreated: this.serverCreated,
2632
- createdBy: this.createdBy,
2633
- modified: this.modified,
2634
- serverModified: this.serverModified,
2635
- modifiedBy: this.modifiedBy,
2636
- createdByName: this.createdByName,
2637
- modifiedByName: this.modifiedByName,
2638
- account: this.account,
2639
- job: this.job,
2640
- assignee: this.assignee,
2641
- done: this.done,
2642
- dueDate: this.dueDate,
2643
- taskType: this.taskType,
2644
- title: this.title,
2645
- jobReference: this.jobReference
2646
- };
2647
- }
2648
- toApiDto(options) {
2649
- return Object.assign(Object.assign({}, super.toApiDto(options)), { assignee: this.assignee, done: this.done, dueDate: this.dueDate, taskType: this.taskType, title: this.title });
2650
- }
2651
- static toApiPatchDto(item) {
2652
- return only(item, [
2653
- 'created',
2654
- 'modified',
2655
- 'assignee',
2656
- 'done',
2657
- 'dueDate',
2658
- 'taskType',
2659
- 'title'
2660
- ]);
2661
- }
2662
- }
2663
-
2664
- class VasVehicleModel extends VasAccountObjectModel {
2665
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, registration, make, model, archived, description) {
2666
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account);
2667
- this.id = id;
2668
- this.created = created;
2669
- this.serverCreated = serverCreated;
2670
- this.createdBy = createdBy;
2671
- this.modified = modified;
2672
- this.serverModified = serverModified;
2673
- this.modifiedBy = modifiedBy;
2674
- this.createdByName = createdByName;
2675
- this.modifiedByName = modifiedByName;
2676
- this.account = account;
2677
- this.registration = registration;
2678
- this.make = make;
2679
- this.model = model;
2680
- this.archived = archived;
2681
- this.description = description;
2682
- }
2683
- static fromDto(dto) {
2684
- return new VasVehicleModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.createdByName || '', dto.modifiedByName || '', dto.account || '', dto.registration || '', dto.make || '', dto.model || '', dto.archived || false, dto.description || '');
2685
- }
2686
- toDto() {
2687
- return {
2688
- id: this.id,
2689
- created: this.created,
2690
- serverCreated: this.serverCreated,
2691
- createdBy: this.createdBy,
2692
- modified: this.modified,
2693
- serverModified: this.serverModified,
2694
- modifiedBy: this.modifiedBy,
2695
- createdByName: this.createdByName,
2696
- modifiedByName: this.modifiedByName,
2697
- account: this.account,
2698
- registration: this.registration,
2699
- make: this.make,
2700
- model: this.model,
2701
- archived: this.archived,
2702
- description: this.description
2703
- };
2704
- }
2705
- toApiDto(options) {
2706
- return {
2707
- id: this.id,
2708
- created: this.created,
2709
- modified: this.modified,
2710
- account: this.account,
2711
- registration: this.registration,
2712
- make: this.make,
2713
- model: this.model,
2714
- archived: this.archived,
2715
- description: this.description
2716
- };
2717
- }
2718
- static toApiPatchDto(dto) {
2719
- return only(dto, [
2720
- 'created',
2721
- 'modified',
2722
- 'registration',
2723
- 'make',
2724
- 'model',
2725
- 'description',
2726
- 'archived'
2727
- ]);
2728
- }
2729
- }
2730
-
2731
- /**
2732
- * Generated bundle index. Do not edit.
2733
- */
2734
-
2735
- export { VasAccountIndexingMode, VasAccountObjectModel, VasBaseModel, VasBranchModel, VasContactModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFieldModel, VasFileModel, VasFireUserModel, VasFormConfigModel, VasFormModel, VasGroupModel, VasInstructionJobFieldModel, VasInstructionJobModel, VasInstructionModel, VasInstructionProviderModel, VasInvitationModel, VasInvitationTypeEnum, VasJobCopyModel, VasJobDataModel, VasJobEmailModel, VasJobModel, VasLookupModel, VasMembershipModel, VasNoteModel, VasReportLayoutModel, VasReportModel, VasReportRequestModel, VasRestrictedAccountObjectModel, VasTaskModel, VasUserModel, VasVehicleModel, getEmptyGeoLocation, isCameraControlValueV1, isFileDto, isJobAutomationStep, isJobControlsStep, isJobEmailFormStep, isJobNotePromptStep, isJobSetDatetimeStep, isJobSetJobStatusStep, isJobSetValueStep, prepareFieldApiValue };
2736
- //# sourceMappingURL=ironcode-vas-lib.mjs.map