@ironcode/vas-lib 2.3.0 → 3.0.0-alpha.10

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 (143) hide show
  1. package/cjs/lib/control-value/vas-camera-control-value.model.d.ts +6 -2
  2. package/cjs/lib/control-value/vas-camera-control-value.model.d.ts.map +1 -1
  3. package/cjs/lib/control-value/vas-camera-control-value.model.js +10 -0
  4. package/cjs/lib/control-value/vas-camera-control-value.model.js.map +1 -1
  5. package/cjs/lib/entity/vas-base.model.d.ts +1 -1
  6. package/cjs/lib/entity/vas-base.model.d.ts.map +1 -1
  7. package/cjs/lib/entity/vas-base.model.js.map +1 -1
  8. package/cjs/lib/entity/vas-control.model.d.ts +4 -4
  9. package/cjs/lib/entity/vas-control.model.d.ts.map +1 -1
  10. package/cjs/lib/entity/vas-control.model.js +1 -1
  11. package/cjs/lib/entity/vas-control.model.js.map +1 -1
  12. package/cjs/lib/entity/vas-field.dto.d.ts +4 -7
  13. package/cjs/lib/entity/vas-field.dto.d.ts.map +1 -1
  14. package/cjs/lib/entity/vas-field.dto.js.map +1 -1
  15. package/cjs/lib/entity/vas-field.model.d.ts +4 -4
  16. package/cjs/lib/entity/vas-field.model.d.ts.map +1 -1
  17. package/cjs/lib/entity/vas-field.model.js +1 -1
  18. package/cjs/lib/entity/vas-field.model.js.map +1 -1
  19. package/cjs/lib/entity/vas-form.model.d.ts +4 -4
  20. package/cjs/lib/entity/vas-form.model.d.ts.map +1 -1
  21. package/cjs/lib/entity/vas-form.model.js +1 -1
  22. package/cjs/lib/entity/vas-form.model.js.map +1 -1
  23. package/cjs/lib/entity/vas-group.model.d.ts +2 -2
  24. package/cjs/lib/entity/vas-group.model.d.ts.map +1 -1
  25. package/cjs/lib/entity/vas-group.model.js.map +1 -1
  26. package/cjs/lib/entity/vas-job-copy.d.ts +12 -12
  27. package/cjs/lib/entity/vas-job-copy.d.ts.map +1 -1
  28. package/cjs/lib/entity/vas-job-copy.js.map +1 -1
  29. package/cjs/lib/entity/vas-job.dto.d.ts +12 -6
  30. package/cjs/lib/entity/vas-job.dto.d.ts.map +1 -1
  31. package/cjs/lib/entity/vas-job.dto.js.map +1 -1
  32. package/cjs/lib/entity/vas-job.model.d.ts +34 -142
  33. package/cjs/lib/entity/vas-job.model.d.ts.map +1 -1
  34. package/cjs/lib/entity/vas-job.model.js +248 -341
  35. package/cjs/lib/entity/vas-job.model.js.map +1 -1
  36. package/cjs/lib/model/estimate-control/estimate-control-value.dto.d.ts +14 -0
  37. package/cjs/lib/model/estimate-control/estimate-control-value.dto.d.ts.map +1 -0
  38. package/cjs/lib/model/estimate-control/estimate-control-value.dto.js +3 -0
  39. package/cjs/lib/model/estimate-control/estimate-control-value.dto.js.map +1 -0
  40. package/cjs/lib/model/estimate-control/estimate-control-value.model.d.ts +11 -0
  41. package/cjs/lib/model/estimate-control/estimate-control-value.model.d.ts.map +1 -0
  42. package/cjs/lib/model/estimate-control/estimate-control-value.model.js +84 -0
  43. package/cjs/lib/model/estimate-control/estimate-control-value.model.js.map +1 -0
  44. package/cjs/lib/model/estimate-control/estimate-item.dto.d.ts +16 -0
  45. package/cjs/lib/model/estimate-control/estimate-item.dto.d.ts.map +1 -0
  46. package/cjs/lib/model/estimate-control/estimate-item.dto.js +3 -0
  47. package/cjs/lib/model/estimate-control/estimate-item.dto.js.map +1 -0
  48. package/cjs/lib/model/estimate-control/estimate-item.model.d.ts +24 -0
  49. package/cjs/lib/model/estimate-control/estimate-item.model.d.ts.map +1 -0
  50. package/cjs/lib/model/estimate-control/estimate-item.model.js +121 -0
  51. package/cjs/lib/model/estimate-control/estimate-item.model.js.map +1 -0
  52. package/cjs/lib/model/estimate-control/estimate.dto.d.ts +37 -0
  53. package/cjs/lib/model/estimate-control/estimate.dto.d.ts.map +1 -0
  54. package/cjs/lib/model/estimate-control/estimate.dto.js +3 -0
  55. package/cjs/lib/model/estimate-control/estimate.dto.js.map +1 -0
  56. package/cjs/lib/model/estimate-control/estimate.model.d.ts +55 -0
  57. package/cjs/lib/model/estimate-control/estimate.model.d.ts.map +1 -0
  58. package/cjs/lib/model/estimate-control/estimate.model.js +279 -0
  59. package/cjs/lib/model/estimate-control/estimate.model.js.map +1 -0
  60. package/cjs/lib/model/estimate-control/estimate.types.d.ts +3 -0
  61. package/cjs/lib/model/estimate-control/estimate.types.d.ts.map +1 -0
  62. package/cjs/lib/model/estimate-control/estimate.types.js +3 -0
  63. package/cjs/lib/model/estimate-control/estimate.types.js.map +1 -0
  64. package/cjs/lib/model/estimate-control/index.d.ts +8 -0
  65. package/cjs/lib/model/estimate-control/index.d.ts.map +1 -0
  66. package/cjs/lib/model/estimate-control/index.js +11 -0
  67. package/cjs/lib/model/estimate-control/index.js.map +1 -0
  68. package/cjs/lib/model/firebase-document-meta.interface.d.ts +6 -0
  69. package/cjs/lib/model/firebase-document-meta.interface.d.ts.map +1 -0
  70. package/cjs/lib/model/firebase-document-meta.interface.js +3 -0
  71. package/cjs/lib/model/firebase-document-meta.interface.js.map +1 -0
  72. package/cjs/lib/model/index.d.ts +3 -0
  73. package/cjs/lib/model/index.d.ts.map +1 -1
  74. package/cjs/lib/model/index.js +3 -0
  75. package/cjs/lib/model/index.js.map +1 -1
  76. package/cjs/lib/model/report-invocation.d.ts +40 -0
  77. package/cjs/lib/model/report-invocation.d.ts.map +1 -0
  78. package/cjs/lib/model/report-invocation.js +3 -0
  79. package/cjs/lib/model/report-invocation.js.map +1 -0
  80. package/cjs/lib/utils/get-value-by-path.d.ts +5 -16
  81. package/cjs/lib/utils/get-value-by-path.d.ts.map +1 -1
  82. package/cjs/lib/utils/get-value-by-path.js +48 -59
  83. package/cjs/lib/utils/get-value-by-path.js.map +1 -1
  84. package/cjs/lib/utils/index.d.ts +8 -0
  85. package/cjs/lib/utils/index.d.ts.map +1 -0
  86. package/cjs/lib/utils/index.js +11 -0
  87. package/cjs/lib/utils/index.js.map +1 -0
  88. package/cjs/lib/utils/is-array-string.d.ts +3 -0
  89. package/cjs/lib/utils/is-array-string.d.ts.map +1 -1
  90. package/cjs/lib/utils/is-array-string.js +3 -0
  91. package/cjs/lib/utils/is-array-string.js.map +1 -1
  92. package/cjs/lib/utils/is-numeric.d.ts +2 -0
  93. package/cjs/lib/utils/is-numeric.d.ts.map +1 -0
  94. package/cjs/lib/utils/is-numeric.js +10 -0
  95. package/cjs/lib/utils/is-numeric.js.map +1 -0
  96. package/cjs/lib/utils/is-plain-object.d.ts +5 -0
  97. package/cjs/lib/utils/is-plain-object.d.ts.map +1 -0
  98. package/cjs/lib/utils/is-plain-object.js +10 -0
  99. package/cjs/lib/utils/is-plain-object.js.map +1 -0
  100. package/cjs/lib/utils/try-json.d.ts +6 -0
  101. package/cjs/lib/utils/try-json.d.ts.map +1 -0
  102. package/cjs/lib/utils/try-json.js +20 -0
  103. package/cjs/lib/utils/try-json.js.map +1 -0
  104. package/cjs/public-api.d.ts +1 -0
  105. package/cjs/public-api.d.ts.map +1 -1
  106. package/cjs/public-api.js +1 -0
  107. package/cjs/public-api.js.map +1 -1
  108. package/fesm2022/ironcode-vas-lib.mjs +831 -390
  109. package/fesm2022/ironcode-vas-lib.mjs.map +1 -1
  110. package/lib/control-value/vas-camera-control-value.model.d.ts +6 -2
  111. package/lib/entity/vas-base.model.d.ts +1 -1
  112. package/lib/entity/vas-control.model.d.ts +4 -4
  113. package/lib/entity/vas-field.dto.d.ts +4 -7
  114. package/lib/entity/vas-field.model.d.ts +4 -4
  115. package/lib/entity/vas-form.model.d.ts +4 -4
  116. package/lib/entity/vas-group.model.d.ts +2 -2
  117. package/lib/entity/vas-job-copy.d.ts +12 -12
  118. package/lib/entity/vas-job.dto.d.ts +12 -6
  119. package/lib/entity/vas-job.model.d.ts +34 -142
  120. package/lib/model/estimate-control/estimate-control-value.dto.d.ts +13 -0
  121. package/lib/model/estimate-control/estimate-control-value.model.d.ts +10 -0
  122. package/lib/model/estimate-control/estimate-item.dto.d.ts +15 -0
  123. package/lib/model/estimate-control/estimate-item.model.d.ts +23 -0
  124. package/lib/model/estimate-control/estimate.dto.d.ts +36 -0
  125. package/lib/model/estimate-control/estimate.model.d.ts +54 -0
  126. package/lib/model/estimate-control/estimate.types.d.ts +2 -0
  127. package/lib/model/estimate-control/index.d.ts +7 -0
  128. package/lib/model/firebase-document-meta.interface.d.ts +5 -0
  129. package/lib/model/index.d.ts +3 -0
  130. package/lib/model/report-invocation.d.ts +39 -0
  131. package/lib/utils/get-value-by-path.d.ts +5 -16
  132. package/lib/utils/index.d.ts +7 -0
  133. package/lib/utils/is-array-string.d.ts +3 -0
  134. package/lib/utils/is-numeric.d.ts +1 -0
  135. package/lib/utils/is-plain-object.d.ts +4 -0
  136. package/lib/utils/omit.d.ts +7 -0
  137. package/lib/utils/try-json.d.ts +5 -0
  138. package/package.json +3 -2
  139. package/public-api.d.ts +1 -0
  140. package/cjs/lib/entity/vas-job.model.spec-data.d.ts +0 -2
  141. package/cjs/lib/entity/vas-job.model.spec-data.d.ts.map +0 -1
  142. package/cjs/lib/entity/vas-job.model.spec-data.js +0 -29
  143. package/cjs/lib/entity/vas-job.model.spec-data.js.map +0 -1
@@ -1,22 +1,30 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.VasJobModel = void 0;
3
+ exports.VasJobDocumentModel = exports.VasJobRelationalModel = exports.VasJobBaseModel = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const vas_file_dto_1 = require("./vas-file.dto");
6
- const angular2_uuid_1 = require("angular2-uuid");
7
6
  const moment_1 = tslib_1.__importDefault(require("moment"));
8
7
  const get_value_by_path_1 = require("../utils/get-value-by-path");
9
- const vas_field_model_1 = require("./vas-field.model");
10
8
  const vas_restricted_account_object_model_1 = require("./vas-restricted-account-object.model");
11
9
  const model_1 = require("../model");
12
10
  const control_value_1 = require("../control-value");
13
- const is_array_string_1 = require("../utils/is-array-string");
14
- const only_1 = require("../utils/only");
11
+ const utils_1 = require("../utils");
12
+ const vas_field_model_1 = require("./vas-field.model");
13
+ const nullables = new Set([
14
+ 'created',
15
+ 'modified',
16
+ 'reference',
17
+ 'jobDate',
18
+ 'followUpDate',
19
+ 'followUpStatus',
20
+ 'followUpNote',
21
+ ]);
22
+ let jobStaticProps;
15
23
  /**
16
- * JobModel
24
+ * VasJobBaseModel
17
25
  */
18
- class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAccountObjectModel {
19
- 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) {
26
+ class VasJobBaseModel extends vas_restricted_account_object_model_1.VasRestrictedAccountObjectModel {
27
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, reference, jobDate, jobStatus, jobStatusLastUpdate, jobType, assigneeId, formId, timeZoneOffset, pendingFields, childModified, version, followUpDate, followUpStatus, followUpNote, geoLocation, files, fields, jobEmails, notes, reports, tasks, instruction) {
20
28
  super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
21
29
  this.id = id;
22
30
  this.created = created;
@@ -32,6 +40,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
32
40
  this.reference = reference;
33
41
  this.jobDate = jobDate;
34
42
  this.jobStatus = jobStatus;
43
+ this.jobStatusLastUpdate = jobStatusLastUpdate;
35
44
  this.jobType = jobType;
36
45
  this.assigneeId = assigneeId;
37
46
  this.formId = formId;
@@ -39,8 +48,9 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
39
48
  this.pendingFields = pendingFields;
40
49
  this.childModified = childModified;
41
50
  this.version = version;
42
- this.createdByDisplayName = createdByDisplayName;
43
- this.modifiedByDisplayName = modifiedByDisplayName;
51
+ this.followUpDate = followUpDate;
52
+ this.followUpStatus = followUpStatus;
53
+ this.followUpNote = followUpNote;
44
54
  this.geoLocation = geoLocation;
45
55
  this.files = files;
46
56
  this.fields = fields;
@@ -50,103 +60,21 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
50
60
  this.tasks = tasks;
51
61
  this.instruction = instruction;
52
62
  }
53
- /**
54
- * Returns this with the dynamic interface
55
- * @return {VasJobModelDynamicInterface}
56
- */
57
- get $this() {
58
- return this;
63
+ get createdByDisplayName() {
64
+ return this.createdByName;
59
65
  }
60
- /**
61
- * Returns a list of Job dynamic properties i.e. those that are added by the
62
- * dynamic forms
63
- */
64
- get dynamicProperties() {
65
- const nativeProps = this.staticProperties;
66
- return Object
67
- .getOwnPropertyNames(this)
68
- .filter(prop => !nativeProps.includes(prop));
66
+ get modifiedByDisplayName() {
67
+ return this.modifiedByName;
69
68
  }
70
69
  /**
71
- * Returns the list of properties of the Job type
70
+ * Return the list of Job properties
72
71
  */
73
72
  get staticProperties() {
74
- return Object.getOwnPropertyNames(VasJobModel.empty());
75
- }
76
- /**
77
- * @return {VasJobModel}
78
- */
79
- static empty() {
80
- return new VasJobModel('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', (0, moment_1.default)().utcOffset(), 0, '', 0, '', '', (0, model_1.getEmptyGeoLocation)(), [], [], [], [], [], [], null);
81
- }
82
- static fromDto(dto) {
83
- 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 || (0, moment_1.default)().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.createdByDisplayName || '', dto.modifiedByDisplayName || '', dto.geoLocation || (0, model_1.getEmptyGeoLocation)(), dto.files || [], dto.fields || [], dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
84
- const emptyKeys = model.staticProperties;
85
- Object
86
- .keys(dto)
87
- .filter(key => emptyKeys.indexOf(key) === -1)
88
- .forEach((key) => model.$this[key] = dto[key]);
89
- return model;
90
- }
91
- /**
92
- * This method will instantiate a new JobModel. The difference with this
93
- * method of instantiation is that we are coming from a relation frame i.e.
94
- * the job has a list of {@link VasFieldDto} instead of a Job document.
95
- *
96
- */
97
- static fromRelational(dto, form) {
98
- 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 || (0, moment_1.default)().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.createdByDisplayName || '', dto.modifiedByDisplayName || '', dto.geoLocation || (0, model_1.getEmptyGeoLocation)(), dto.files || [], dto.fields || [], dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
99
- form.groups
100
- .forEach(group => {
101
- group.controls
102
- .forEach(control => {
103
- var _a;
104
- const field = (_a = dto.fields) === null || _a === void 0 ? void 0 : _a.find(f => f.control === control.id);
105
- if (!field) {
106
- return;
107
- }
108
- model.getGroup(group.name)[control.name] = field.value;
109
- });
110
- });
111
- return model;
112
- }
113
- /**
114
- * @param {VasFormModel} formModel
115
- * @return {Record<string, VasFieldDtoValue>}
116
- */
117
- getFields(formModel) {
118
- const fields = {};
119
- formModel.groups
120
- .forEach(group => {
121
- group.controls.forEach(control => {
122
- (fields)[control.reportTemplateName] =
123
- this.getValueByPath([group.name, control.name]) || null;
124
- });
125
- });
126
- return fields;
127
- }
128
- /**
129
- * Will return an object whose keys are the names of all fields in the job.
130
- * This method is similar to `getFields` except that this method will only
131
- * return values where a value was set, as opposed to `getFields` which will
132
- * return a value for every control even if no value was set, because it uses
133
- * the form to drive the logic. Note also this method will return values for
134
- * any Fields in the fields array.
135
- * @return {Record<string, VasFieldDtoValue>}
136
- */
137
- getFields2() {
138
- let fields = {};
139
- this.dynamicProperties
140
- .forEach((groupName) => {
141
- Object
142
- .keys(this.$this[groupName])
143
- .forEach(controlName => {
144
- fields[controlName] =
145
- this.getValueByPath([groupName, controlName]) || null;
146
- });
147
- }, {});
148
- this.fields.forEach(field => fields[field.controlName] = field.value);
149
- return fields;
73
+ if (jobStaticProps) {
74
+ return jobStaticProps;
75
+ }
76
+ return jobStaticProps =
77
+ new Set(Object.getOwnPropertyNames(VasJobDocumentModel.empty()));
150
78
  }
151
79
  /**
152
80
  * Returns an object describing how many attachments were added to this job
@@ -156,22 +84,12 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
156
84
  * job was created
157
85
  */
158
86
  getFilesUploadStatus(formModel) {
159
- const pathsWithValue = formModel
160
- .getCameraControlPaths()
161
- .map(path => {
162
- const value = this.getValueByPath(path);
163
- if (value && !!value.id) {
164
- return path;
165
- }
166
- return null;
167
- })
168
- .filter(path => path !== null ? path : null)
169
- .filter(is_array_string_1.isArrayString);
170
- let total = pathsWithValue.length;
171
- total += this.files.length;
87
+ const cameraFieldValues = Object
88
+ .values(this.fields)
89
+ .filter(value => (0, control_value_1.isCameraControlValueV2)(value) || (0, control_value_1.isCameraControlValueV1)(value));
90
+ let total = cameraFieldValues.length + this.files.length;
172
91
  // calculate the number of camera images still to upload
173
- let pending = pathsWithValue
174
- .map(path => this.getValueByPath(path))
92
+ let pending = cameraFieldValues
175
93
  .map((value) => {
176
94
  if ((0, vas_file_dto_1.isFileDto)(value)) {
177
95
  return value.id && value.status !== 'COMPLETE';
@@ -184,218 +102,18 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
184
102
  })
185
103
  .filter(hasUploaded => hasUploaded)
186
104
  .length;
187
- // add total from files that are pending
188
- pending += this.files
189
- .filter(value => value.status !== 'COMPLETE')
190
- .length;
105
+ // add count of job.files that are complete
106
+ pending += this.files.filter(value => value.status !== 'COMPLETE').length;
191
107
  return {
192
108
  pending,
193
109
  total
194
110
  };
195
111
  }
196
- /**
197
- * This method will return the dynamic property from the JobModel that
198
- * represent a group (from a form).
199
- *
200
- * @param name the name of the group
201
- * @param init if true (default) and group is not found, initialise an empty
202
- * group, otherwise throw an error
203
- */
204
- getGroup(name, init = true) {
205
- let prop;
206
- if (this.staticProperties.includes(name)) {
207
- throw Error(`invalid group name ${name}, not a dynamic property`);
208
- }
209
- else if (this.$this[name] === undefined) {
210
- if (init) {
211
- prop = this.$this[name] = {};
212
- }
213
- else {
214
- throw Error(`invalid group name ${name}, not found`);
215
- }
216
- }
217
- else {
218
- prop = this.$this[name];
219
- if (typeof prop !== 'object') {
220
- throw Error(`invalid group name ${name}, not an object`);
221
- }
222
- }
223
- return prop;
224
- }
225
112
  /**
226
113
  * @param path path segments
227
114
  */
228
115
  getValueByPath(path = []) {
229
- return (0, get_value_by_path_1.getValueByPath)(path, this.$this);
230
- }
231
- /**
232
- * In order to understand why we need this method it is important to
233
- * understand that within the system, Jobs can be represented in one of two
234
- * ways, document and relational.
235
- *
236
- * The important distinction is how values submitted by a form are stored.
237
- *
238
- * Jobs stored as documents (JSON objects) will store user values, as dynamic
239
- * properties of the document.
240
- *
241
- * Whereas, Jobs stored as relational, will store user values in an array of
242
- * {@link VasFieldDto} objects.
243
- *
244
- * Depending on where we are in the system, either one of these approaches can
245
- * be more useful than the other.
246
- *
247
- * This method, assumes that the JobModel has been instantiated from a
248
- * document representation, and serves to hydrate the fields array. In order
249
- * to achieve this, knowledge of the {@link VasFormDto} that created the job
250
- * is required.
251
- *
252
- *
253
- * Job in document representation
254
- * {
255
- * id: <guid>,
256
- * reference: "something"
257
- * <other static job properties>...
258
- * foo: {
259
- * bar: "value"
260
- * }
261
- * }
262
- *
263
- * Job in relational representation
264
- * {
265
- * id: <guid>,
266
- * reference: "something"
267
- * <other static job properties>...
268
- * <will not have dynamic properties>...
269
- * fields: [
270
- * {
271
- * id: <guid>,
272
- * <other field properties>,
273
- * value: "value"
274
- * }
275
- * ]
276
- * }
277
- *
278
- *
279
- * @param formModel the VasFormModel that was used to create the job
280
- * @param controlFieldIdMap This is used to determine the id each field.
281
- * Either one will be found in the map, or a new one is generated.
282
- * @param controlNames if a value is provided, it will be used
283
- * to filter the fields that are returned.
284
- * @return {Array<VasFieldDto>}
285
- */
286
- hydrateFields(formModel, controlFieldIdMap = new Map(), controlNames) {
287
- const fields = [];
288
- formModel.groups
289
- .forEach(group => {
290
- group.controls.forEach(control => {
291
- if (!control.name.startsWith('fields.')) {
292
- return;
293
- }
294
- if (controlNames && !controlNames.includes(control.name)) {
295
- return;
296
- }
297
- fields.push(vas_field_model_1.VasFieldModel.fromDto({
298
- // if the controlId exists in the map, use the associated fieldId,
299
- // otherwise generate a new id for the field.
300
- id: controlFieldIdMap.get(control.id) || angular2_uuid_1.UUID.UUID(),
301
- account: this.account,
302
- job: this.id,
303
- createdBy: this.createdBy,
304
- created: this.created,
305
- modifiedBy: this.modifiedBy,
306
- modified: this.modified,
307
- control: control.id,
308
- value: this.getValueByPath([group.name, control.name])
309
- }));
310
- });
311
- });
312
- this.fields = fields;
313
- }
314
- /**
315
- * A very non sophisticated way to set values in the job via paths
316
- *
317
- * For example:
318
- *
319
- * setValueByPath('value', ['foo', 'bar']);
320
- *
321
- * will make results in job
322
- * {
323
- * foo: {
324
- * bar: 'value'
325
- * }
326
- * }
327
- *
328
- * @param value the value to set
329
- * @param path path segments
330
- */
331
- setValueByPath(value, path = []) {
332
- switch (path.length) {
333
- case 0: {
334
- return;
335
- }
336
- case 1: {
337
- this[path[0]] = value;
338
- return;
339
- }
340
- case 2: {
341
- // eslint-disable-next-line max-len
342
- this.$this[path[0]][path[1]] = value;
343
- return;
344
- }
345
- case 3: {
346
- // eslint-disable-next-line max-len
347
- this.$this[path[0]][path[1]][path[2]] = value;
348
- return;
349
- }
350
- default: {
351
- throw Error('path has too many segments');
352
- }
353
- }
354
- }
355
- /**
356
- * @param staticOnly if true, will only output values for the static
357
- * properties in the dto
358
- */
359
- toDto(staticOnly = false) {
360
- if (staticOnly) {
361
- return {
362
- id: this.id,
363
- created: this.created,
364
- createdBy: this.createdBy,
365
- modified: this.modified,
366
- modifiedBy: this.modifiedBy,
367
- serverCreated: this.serverCreated,
368
- serverModified: this.serverModified,
369
- createdByName: this.createdByName,
370
- modifiedByName: this.modifiedByName,
371
- account: this.account,
372
- accessGroup: this.accessGroup,
373
- reference: this.reference,
374
- jobDate: this.jobDate,
375
- jobStatus: this.jobStatus,
376
- jobType: this.jobType,
377
- assigneeId: this.assigneeId,
378
- formId: this.formId,
379
- timeZoneOffset: this.timeZoneOffset,
380
- pendingFields: this.pendingFields,
381
- childModified: this.childModified,
382
- version: this.version,
383
- createdByDisplayName: this.createdByDisplayName,
384
- modifiedByDisplayName: this.modifiedByDisplayName,
385
- geoLocation: this.geoLocation,
386
- files: this.files,
387
- fields: this.fields,
388
- jobEmails: this.jobEmails,
389
- notes: this.notes,
390
- reports: this.reports,
391
- tasks: this.tasks,
392
- instruction: this.instruction
393
- };
394
- }
395
- const dto = {};
396
- [...this.staticProperties, ...this.dynamicProperties]
397
- .forEach(prop => dto[prop] = this.$this[prop]);
398
- return dto;
116
+ return (0, get_value_by_path_1.getValueByPath)(Array.isArray(path) ? path : path.split('.'), this);
399
117
  }
400
118
  /**
401
119
  * This method will parse a syntax that allows us to build strings from the
@@ -429,7 +147,6 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
429
147
  if (!value || typeof value !== 'string') {
430
148
  return '';
431
149
  }
432
- const fields = this.getFields2();
433
150
  return value.replace(/({[^}]*})/g, (match, token) => {
434
151
  const syntax = token.substring(1, token.length - 1);
435
152
  let [key, filter] = syntax.split('|');
@@ -456,23 +173,10 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
456
173
  result = (this.getValueByPath(path) || '').toString();
457
174
  }
458
175
  else if (objectKey === 'fields') {
459
- result = ((0, get_value_by_path_1.getValueByPath)(['fields.' + path.shift(), ...path], fields) || '').toString();
176
+ result = (this.getValueByPath(['fields', ...path]) || '').toString();
460
177
  }
461
- else if (objectKey.length) {
462
- if (options.objects) {
463
- if (options.objects[objectKey] === undefined) {
464
- console.debug(`objectKey ${objectKey} is not present in options.object`);
465
- result = '';
466
- }
467
- else {
468
- result = ((0, get_value_by_path_1.getValueByPath)(path, options.objects[objectKey]) || '')
469
- .toString();
470
- }
471
- }
472
- else {
473
- console.debug(`objectKey ${objectKey} was used but options.object is not set`);
474
- return '';
475
- }
178
+ else if (objectKey.length && options.objects && options.objects[objectKey] !== undefined) {
179
+ result = ((0, get_value_by_path_1.getValueByPath)(path, options.objects[objectKey]) || '').toString();
476
180
  }
477
181
  else {
478
182
  return '';
@@ -505,7 +209,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
505
209
  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 || '~' });
506
210
  }
507
211
  static toApiPatchDto(item) {
508
- return (0, only_1.only)(item, [
212
+ return (0, utils_1.only)(item, [
509
213
  'created',
510
214
  'modified',
511
215
  'reference',
@@ -516,9 +220,212 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
516
220
  'assigneeId',
517
221
  'timeZoneOffset',
518
222
  'pendingFields',
519
- 'lastForm'
520
- ]);
223
+ 'formId',
224
+ 'followUpDate',
225
+ 'followUpStatus',
226
+ 'followUpNote',
227
+ ], (value, key) => value[key] === null && nullables.has(key) ? '~' : value[key]);
228
+ }
229
+ }
230
+ exports.VasJobBaseModel = VasJobBaseModel;
231
+ class VasJobRelationalModel extends VasJobBaseModel {
232
+ getValueByPath(path = []) {
233
+ const parts = Array.isArray(path) ? path : path.split('.');
234
+ if (parts[0] === 'fields') {
235
+ return this.getFieldValueByPath(parts[1], parts.slice(2));
236
+ }
237
+ return (0, get_value_by_path_1.getValueByPath)(parts, this);
238
+ }
239
+ getFieldsMap() {
240
+ return this.fields.reduce((p, c) => {
241
+ p[c.controlName] = c.value;
242
+ return p;
243
+ }, {});
244
+ }
245
+ getFieldValueByPath(controlName, path) {
246
+ for (const field of this.fields) {
247
+ if (field.controlName === controlName) {
248
+ if (path.length === 0) {
249
+ return field.value;
250
+ }
251
+ if (field.value === null) {
252
+ return path.length >= 1 ? undefined : null;
253
+ }
254
+ if ((0, utils_1.isPlainObject)(field.value)) {
255
+ return (0, get_value_by_path_1.getValueByPath)(path, field.value);
256
+ }
257
+ return undefined;
258
+ }
259
+ }
260
+ return undefined;
261
+ }
262
+ static fromDto(dto) {
263
+ if (dto.fields !== undefined && !Array.isArray(dto.fields)) {
264
+ throw Error('fields must be an array');
265
+ }
266
+ return new VasJobRelationalModel(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.jobStatusLastUpdate || '', dto.jobType || '', dto.assigneeId || '', dto.formId || dto.lastForm || '', dto.timeZoneOffset || (0, moment_1.default)().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.followUpDate || '', dto.followUpStatus || '', dto.followUpNote || '', dto.geoLocation || (0, model_1.getEmptyGeoLocation)(), dto.files || [], (dto.fields || []).map(f => vas_field_model_1.VasFieldModel.fromDto(f)), dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
267
+ }
268
+ static empty() {
269
+ return new VasJobRelationalModel('', // id
270
+ '', // created
271
+ '', // serverCreated
272
+ '', // createdBy
273
+ '', // modified
274
+ '', // serverModified
275
+ '', // modifiedBy
276
+ '', // createdByName
277
+ '', // modifiedByName
278
+ '', // account
279
+ '', // accessGroup
280
+ '', // reference
281
+ '', // jobDate
282
+ '', // jobStatus
283
+ '', // jobStatusLastUpdate
284
+ '', // jobType
285
+ '', // assigneeId
286
+ '', // formId
287
+ (0, moment_1.default)().utcOffset(), // timeZoneOffset
288
+ 0, // pendingFields: number,
289
+ '', // childModified: string,
290
+ 0, // version: number,
291
+ '', // followUpDate: string,
292
+ '', // followUpStatus: string,
293
+ '', // followUpNote: string,
294
+ (0, model_1.getEmptyGeoLocation)(), // geoLocation: GeoLocation,
295
+ [], // files: Array<VasFileDto>,
296
+ [], // fields: FType,
297
+ [], // jobEmails: Array<VasJobEmailDto>,
298
+ [], // notes: Array<VasNoteDto>,
299
+ [], // reports: Array<VasReportDto>,
300
+ [], // tasks: Array<VasTaskDto>,
301
+ null // instruction: VasInstructionDto | null
302
+ );
303
+ }
304
+ toDto() {
305
+ return {
306
+ id: this.id,
307
+ created: this.created,
308
+ createdBy: this.createdBy,
309
+ modified: this.modified,
310
+ modifiedBy: this.modifiedBy,
311
+ serverCreated: this.serverCreated,
312
+ serverModified: this.serverModified,
313
+ createdByName: this.createdByName,
314
+ modifiedByName: this.modifiedByName,
315
+ account: this.account,
316
+ accessGroup: this.accessGroup,
317
+ reference: this.reference,
318
+ jobDate: this.jobDate,
319
+ jobStatus: this.jobStatus,
320
+ jobStatusLastUpdate: this.jobStatusLastUpdate,
321
+ jobType: this.jobType,
322
+ assigneeId: this.assigneeId,
323
+ formId: this.formId,
324
+ timeZoneOffset: this.timeZoneOffset,
325
+ pendingFields: this.pendingFields,
326
+ childModified: this.childModified,
327
+ version: this.version,
328
+ followUpDate: this.followUpDate,
329
+ followUpStatus: this.followUpStatus,
330
+ followUpNote: this.followUpNote,
331
+ geoLocation: this.geoLocation,
332
+ files: this.files,
333
+ fields: this.fields.map(f => f.toDto()),
334
+ jobEmails: this.jobEmails,
335
+ notes: this.notes,
336
+ reports: this.reports,
337
+ tasks: this.tasks,
338
+ instruction: this.instruction
339
+ };
340
+ }
341
+ }
342
+ exports.VasJobRelationalModel = VasJobRelationalModel;
343
+ class VasJobDocumentModel extends VasJobBaseModel {
344
+ static fromRelationalDto(dto) {
345
+ return new VasJobDocumentModel(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.jobStatusLastUpdate || '', dto.jobType || '', dto.assigneeId || '', dto.formId || dto.lastForm || '', dto.timeZoneOffset || (0, moment_1.default)().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.followUpDate || '', dto.followUpStatus || '', dto.followUpNote || '', dto.geoLocation || (0, model_1.getEmptyGeoLocation)(), dto.files || [], (dto.fields || []).reduce((p, c) => {
346
+ p[c.controlName.replace('fields.', '')] = c.value;
347
+ return p;
348
+ }, {}), dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
349
+ }
350
+ static fromDto(dto) {
351
+ if (dto.fields !== undefined && !(0, utils_1.isPlainObject)(dto.fields)) {
352
+ throw Error('fields must be an object');
353
+ }
354
+ return new VasJobDocumentModel(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.jobStatusLastUpdate || '', dto.jobType || '', dto.assigneeId || '', dto.formId || dto.lastForm || '', dto.timeZoneOffset || (0, moment_1.default)().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.followUpDate || '', dto.followUpStatus || '', dto.followUpNote || '', dto.geoLocation || (0, model_1.getEmptyGeoLocation)(), dto.files || [], dto.fields || {}, dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
355
+ }
356
+ static empty() {
357
+ return new VasJobDocumentModel('', // id
358
+ '', // created
359
+ '', // serverCreated
360
+ '', // createdBy
361
+ '', // modified
362
+ '', // serverModified
363
+ '', // modifiedBy
364
+ '', // createdByName
365
+ '', // modifiedByName
366
+ '', // account
367
+ '', // accessGroup
368
+ '', // reference
369
+ '', // jobDate
370
+ '', // jobStatus
371
+ '', // jobStatusLastUpdate
372
+ '', // jobType
373
+ '', // assigneeId
374
+ '', // formId
375
+ (0, moment_1.default)().utcOffset(), // timeZoneOffset
376
+ 0, // pendingFields: number,
377
+ '', // childModified: string,
378
+ 0, // version: number,
379
+ '', // followUpDate: string,
380
+ '', // followUpStatus: string,
381
+ '', // followUpNote: string,
382
+ (0, model_1.getEmptyGeoLocation)(), // geoLocation: GeoLocation,
383
+ [], // files: Array<VasFileDto>,
384
+ {}, // fields: FType,
385
+ [], // jobEmails: Array<VasJobEmailDto>,
386
+ [], // notes: Array<VasNoteDto>,
387
+ [], // reports: Array<VasReportDto>,
388
+ [], // tasks: Array<VasTaskDto>,
389
+ null // instruction: VasInstructionDto | null
390
+ );
391
+ }
392
+ toDto() {
393
+ return {
394
+ id: this.id,
395
+ created: this.created,
396
+ createdBy: this.createdBy,
397
+ modified: this.modified,
398
+ modifiedBy: this.modifiedBy,
399
+ serverCreated: this.serverCreated,
400
+ serverModified: this.serverModified,
401
+ createdByName: this.createdByName,
402
+ modifiedByName: this.modifiedByName,
403
+ account: this.account,
404
+ accessGroup: this.accessGroup,
405
+ reference: this.reference,
406
+ jobDate: this.jobDate,
407
+ jobStatus: this.jobStatus,
408
+ jobStatusLastUpdate: this.jobStatusLastUpdate,
409
+ jobType: this.jobType,
410
+ assigneeId: this.assigneeId,
411
+ formId: this.formId,
412
+ timeZoneOffset: this.timeZoneOffset,
413
+ pendingFields: this.pendingFields,
414
+ childModified: this.childModified,
415
+ version: this.version,
416
+ followUpDate: this.followUpDate,
417
+ followUpStatus: this.followUpStatus,
418
+ followUpNote: this.followUpNote,
419
+ geoLocation: this.geoLocation,
420
+ files: this.files,
421
+ fields: this.fields,
422
+ jobEmails: this.jobEmails,
423
+ notes: this.notes,
424
+ reports: this.reports,
425
+ tasks: this.tasks,
426
+ instruction: this.instruction
427
+ };
521
428
  }
522
429
  }
523
- exports.VasJobModel = VasJobModel;
430
+ exports.VasJobDocumentModel = VasJobDocumentModel;
524
431
  //# sourceMappingURL=vas-job.model.js.map