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

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 (69) hide show
  1. package/cjs/lib/control-value/vas-camera-control-value.model.d.ts +2 -0
  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-control.model.d.ts +4 -4
  6. package/cjs/lib/entity/vas-control.model.d.ts.map +1 -1
  7. package/cjs/lib/entity/vas-control.model.js +1 -1
  8. package/cjs/lib/entity/vas-control.model.js.map +1 -1
  9. package/cjs/lib/entity/vas-field.dto.d.ts +3 -5
  10. package/cjs/lib/entity/vas-field.dto.d.ts.map +1 -1
  11. package/cjs/lib/entity/vas-field.dto.js.map +1 -1
  12. package/cjs/lib/entity/vas-field.model.d.ts +4 -4
  13. package/cjs/lib/entity/vas-field.model.d.ts.map +1 -1
  14. package/cjs/lib/entity/vas-field.model.js.map +1 -1
  15. package/cjs/lib/entity/vas-form.model.d.ts +3 -3
  16. package/cjs/lib/entity/vas-form.model.d.ts.map +1 -1
  17. package/cjs/lib/entity/vas-form.model.js +1 -1
  18. package/cjs/lib/entity/vas-form.model.js.map +1 -1
  19. package/cjs/lib/entity/vas-group.model.d.ts +2 -2
  20. package/cjs/lib/entity/vas-group.model.d.ts.map +1 -1
  21. package/cjs/lib/entity/vas-group.model.js.map +1 -1
  22. package/cjs/lib/entity/vas-job.dto.d.ts +3 -6
  23. package/cjs/lib/entity/vas-job.dto.d.ts.map +1 -1
  24. package/cjs/lib/entity/vas-job.dto.js.map +1 -1
  25. package/cjs/lib/entity/vas-job.model.d.ts +10 -133
  26. package/cjs/lib/entity/vas-job.model.d.ts.map +1 -1
  27. package/cjs/lib/entity/vas-job.model.js +97 -324
  28. package/cjs/lib/entity/vas-job.model.js.map +1 -1
  29. package/cjs/lib/model/firebase-document-meta.interface.d.ts +6 -0
  30. package/cjs/lib/model/firebase-document-meta.interface.d.ts.map +1 -0
  31. package/cjs/lib/model/firebase-document-meta.interface.js +3 -0
  32. package/cjs/lib/model/firebase-document-meta.interface.js.map +1 -0
  33. package/cjs/lib/model/index.d.ts +1 -0
  34. package/cjs/lib/model/index.d.ts.map +1 -1
  35. package/cjs/lib/model/index.js +1 -0
  36. package/cjs/lib/model/index.js.map +1 -1
  37. package/cjs/lib/utils/get-value-by-path.d.ts +2 -3
  38. package/cjs/lib/utils/get-value-by-path.d.ts.map +1 -1
  39. package/cjs/lib/utils/get-value-by-path.js +1 -1
  40. package/cjs/lib/utils/get-value-by-path.js.map +1 -1
  41. package/cjs/lib/utils/is-plain-object.d.ts +2 -0
  42. package/cjs/lib/utils/is-plain-object.d.ts.map +1 -0
  43. package/cjs/lib/utils/is-plain-object.js +7 -0
  44. package/cjs/lib/utils/is-plain-object.js.map +1 -0
  45. package/cjs/lib/utils/try-json.d.ts +6 -0
  46. package/cjs/lib/utils/try-json.d.ts.map +1 -0
  47. package/cjs/lib/utils/try-json.js +20 -0
  48. package/cjs/lib/utils/try-json.js.map +1 -0
  49. package/fesm2022/ironcode-vas-lib.mjs +126 -328
  50. package/fesm2022/ironcode-vas-lib.mjs.map +1 -1
  51. package/lib/control-value/vas-camera-control-value.model.d.ts +2 -0
  52. package/lib/entity/vas-control.model.d.ts +4 -4
  53. package/lib/entity/vas-field.dto.d.ts +3 -5
  54. package/lib/entity/vas-field.model.d.ts +4 -4
  55. package/lib/entity/vas-form.model.d.ts +3 -3
  56. package/lib/entity/vas-group.model.d.ts +2 -2
  57. package/lib/entity/vas-job.dto.d.ts +3 -6
  58. package/lib/entity/vas-job.model.d.ts +10 -133
  59. package/lib/model/firebase-document-meta.interface.d.ts +5 -0
  60. package/lib/model/index.d.ts +1 -0
  61. package/lib/utils/get-value-by-path.d.ts +2 -3
  62. package/lib/utils/is-plain-object.d.ts +1 -0
  63. package/lib/utils/try-json.d.ts +5 -0
  64. package/package.json +1 -1
  65. package/cjs/lib/entity/vas-job.model.spec-data.d.ts +0 -2
  66. package/cjs/lib/entity/vas-job.model.spec-data.d.ts.map +0 -1
  67. package/cjs/lib/entity/vas-job.model.spec-data.js +0 -29
  68. package/cjs/lib/entity/vas-job.model.spec-data.js.map +0 -1
  69. package/lib/utils/is-array-string.d.ts +0 -1
@@ -3,20 +3,26 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VasJobModel = 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
11
  const only_1 = require("../utils/only");
12
+ const try_json_1 = require("../utils/try-json");
13
+ const is_plain_object_1 = require("../utils/is-plain-object");
14
+ let jobStaticProps;
15
+ function getJobStaticProperties() {
16
+ if (jobStaticProps) {
17
+ return jobStaticProps;
18
+ }
19
+ return jobStaticProps = new Set(Object.getOwnPropertyNames(VasJobModel.empty()));
20
+ }
15
21
  /**
16
22
  * JobModel
17
23
  */
18
24
  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) {
25
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup, reference, jobDate, jobStatus, jobType, assigneeId, formId, timeZoneOffset, pendingFields, childModified, version, geoLocation, files, fields, jobEmails, notes, reports, tasks, instruction) {
20
26
  super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
21
27
  this.id = id;
22
28
  this.created = created;
@@ -39,8 +45,6 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
39
45
  this.pendingFields = pendingFields;
40
46
  this.childModified = childModified;
41
47
  this.version = version;
42
- this.createdByDisplayName = createdByDisplayName;
43
- this.modifiedByDisplayName = modifiedByDisplayName;
44
48
  this.geoLocation = geoLocation;
45
49
  this.files = files;
46
50
  this.fields = fields;
@@ -50,103 +54,62 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
50
54
  this.tasks = tasks;
51
55
  this.instruction = instruction;
52
56
  }
53
- /**
54
- * Returns this with the dynamic interface
55
- * @return {VasJobModelDynamicInterface}
56
- */
57
- get $this() {
58
- return this;
57
+ get createdByDisplayName() {
58
+ return this.createdByName;
59
59
  }
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));
60
+ get modifiedByDisplayName() {
61
+ return this.modifiedByName;
69
62
  }
70
63
  /**
71
- * Returns the list of properties of the Job type
64
+ * Return the list of Job properties
72
65
  */
73
66
  get staticProperties() {
74
- return Object.getOwnPropertyNames(VasJobModel.empty());
67
+ if (jobStaticProps) {
68
+ return jobStaticProps;
69
+ }
70
+ return jobStaticProps = new Set(Object.getOwnPropertyNames(VasJobModel.empty()));
75
71
  }
76
72
  /**
77
73
  * @return {VasJobModel}
78
74
  */
79
75
  static empty() {
80
- return new VasJobModel('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', (0, moment_1.default)().utcOffset(), 0, '', 0, '', '', (0, model_1.getEmptyGeoLocation)(), [], [], [], [], [], [], null);
76
+ return new VasJobModel('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', (0, moment_1.default)().utcOffset(), 0, '', 0, (0, model_1.getEmptyGeoLocation)(), [], {}, [], [], [], [], null);
81
77
  }
82
78
  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
- });
79
+ // we have changed the job model and stopped using the dynamic properties
80
+ // from form group names to hold fields. Instead, we store a simple object
81
+ // where the control name (minus the "fields." prefix) is the key, and the
82
+ // field value is the value. However, we have to cater for data that may
83
+ // be persisted in the old structure, or an API response where fields is an
84
+ // array of VasFieldDto.
85
+ // 1: if dto.fields is already an object, we use the existing value
86
+ const fields = (0, is_plain_object_1.isPlainObject)(dto.fields) ?
87
+ dto.fields :
88
+ {};
89
+ // 2: if dto.fields is an array, we're handling a vas-rest response, we
90
+ // iterate over the fields and update the fields object.
91
+ Array.isArray(dto.fields) && dto.fields.forEach((field) => {
92
+ fields[field.controlName.replace('fields.', '')] = (0, try_json_1.tryJson)(field.value);
125
93
  });
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) => {
94
+ // 3: if `fields` still has no keys, we're restoring a VasJobDto object that
95
+ // was saved in the old "form-group" style, where dynamic keys are
96
+ // derived from the form-group names. We'll iterate over those keys, and
97
+ // update the `fields` object. Once this model is serialized back to a
98
+ // dto, it will have the new shape.
99
+ if (Object.keys(fields).length === 0) {
141
100
  Object
142
- .keys(this.$this[groupName])
143
- .forEach(controlName => {
144
- fields[controlName] =
145
- this.getValueByPath([groupName, controlName]) || null;
101
+ .keys(dto)
102
+ .filter(key => !getJobStaticProperties().has(key))
103
+ .forEach(groupName => {
104
+ Object
105
+ .keys(dto[groupName])
106
+ .forEach(controlName => {
107
+ const cn = controlName.replace('fields.', '');
108
+ fields[cn] = dto[groupName][cn];
109
+ });
146
110
  });
147
- }, {});
148
- this.fields.forEach(field => fields[field.controlName] = field.value);
149
- return fields;
111
+ }
112
+ return 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.geoLocation || (0, model_1.getEmptyGeoLocation)(), dto.files || [], fields, dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
150
113
  }
151
114
  /**
152
115
  * Returns an object describing how many attachments were added to this job
@@ -156,22 +119,12 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
156
119
  * job was created
157
120
  */
158
121
  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;
122
+ const cameraFieldValues = Object
123
+ .values(this.fields)
124
+ .filter(value => (0, control_value_1.isCameraControlValueV2)(value) || (0, control_value_1.isCameraControlValueV1)(value));
125
+ let total = cameraFieldValues.length + this.files.length;
172
126
  // calculate the number of camera images still to upload
173
- let pending = pathsWithValue
174
- .map(path => this.getValueByPath(path))
127
+ let pending = cameraFieldValues
175
128
  .map((value) => {
176
129
  if ((0, vas_file_dto_1.isFileDto)(value)) {
177
130
  return value.id && value.status !== 'COMPLETE';
@@ -184,218 +137,51 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
184
137
  })
185
138
  .filter(hasUploaded => hasUploaded)
186
139
  .length;
187
- // add total from files that are pending
188
- pending += this.files
189
- .filter(value => value.status !== 'COMPLETE')
190
- .length;
140
+ // add count of job.files that are complete
141
+ pending += this.files.filter(value => value.status !== 'COMPLETE').length;
191
142
  return {
192
143
  pending,
193
144
  total
194
145
  };
195
146
  }
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
147
  /**
226
148
  * @param path path segments
227
149
  */
228
150
  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
- }
151
+ return (0, get_value_by_path_1.getValueByPath)(Array.isArray(path) ? path : path.split('.'), this);
354
152
  }
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;
153
+ toDto() {
154
+ return {
155
+ id: this.id,
156
+ created: this.created,
157
+ createdBy: this.createdBy,
158
+ modified: this.modified,
159
+ modifiedBy: this.modifiedBy,
160
+ serverCreated: this.serverCreated,
161
+ serverModified: this.serverModified,
162
+ createdByName: this.createdByName,
163
+ modifiedByName: this.modifiedByName,
164
+ account: this.account,
165
+ accessGroup: this.accessGroup,
166
+ reference: this.reference,
167
+ jobDate: this.jobDate,
168
+ jobStatus: this.jobStatus,
169
+ jobType: this.jobType,
170
+ assigneeId: this.assigneeId,
171
+ formId: this.formId,
172
+ timeZoneOffset: this.timeZoneOffset,
173
+ pendingFields: this.pendingFields,
174
+ childModified: this.childModified,
175
+ version: this.version,
176
+ geoLocation: this.geoLocation,
177
+ files: this.files,
178
+ fields: this.fields,
179
+ jobEmails: this.jobEmails,
180
+ notes: this.notes,
181
+ reports: this.reports,
182
+ tasks: this.tasks,
183
+ instruction: this.instruction
184
+ };
399
185
  }
400
186
  /**
401
187
  * This method will parse a syntax that allows us to build strings from the
@@ -429,7 +215,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
429
215
  if (!value || typeof value !== 'string') {
430
216
  return '';
431
217
  }
432
- const fields = this.getFields2();
218
+ const fields = this.fields;
433
219
  return value.replace(/({[^}]*})/g, (match, token) => {
434
220
  const syntax = token.substring(1, token.length - 1);
435
221
  let [key, filter] = syntax.split('|');
@@ -455,24 +241,11 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
455
241
  if (objectKey === 'job') {
456
242
  result = (this.getValueByPath(path) || '').toString();
457
243
  }
458
- else if (objectKey === 'fields') {
459
- result = ((0, get_value_by_path_1.getValueByPath)(['fields.' + path.shift(), ...path], fields) || '').toString();
244
+ else if (objectKey === 'fields' || this.fields[path[0]] !== undefined) {
245
+ result = ((0, get_value_by_path_1.getValueByPath)(path, fields) || '').toString();
460
246
  }
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
- }
247
+ else if (objectKey.length && options.objects && options.objects[objectKey] !== undefined) {
248
+ result = ((0, get_value_by_path_1.getValueByPath)(path, options.objects[objectKey]) || '').toString();
476
249
  }
477
250
  else {
478
251
  return '';
@@ -516,7 +289,7 @@ class VasJobModel extends vas_restricted_account_object_model_1.VasRestrictedAcc
516
289
  'assigneeId',
517
290
  'timeZoneOffset',
518
291
  'pendingFields',
519
- 'lastForm'
292
+ 'formId'
520
293
  ]);
521
294
  }
522
295
  }