@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
@@ -8,6 +8,15 @@ function isCameraControlValueV1(object) {
8
8
  && 'url' in object
9
9
  && 'id' in object;
10
10
  }
11
+ function isCameraControlValueV2(object) {
12
+ return object instanceof Object
13
+ && 'id' in object
14
+ && 'name' in object
15
+ && 'fileSize' in object
16
+ && 'mimeType' in object
17
+ && 'sequence' in object
18
+ && 'config' in object;
19
+ }
11
20
 
12
21
  var VasControlConfigDirection;
13
22
  (function (VasControlConfigDirection) {
@@ -1341,7 +1350,7 @@ class VasControlModel extends VasRestrictedAccountObjectModel {
1341
1350
  }
1342
1351
  /**
1343
1352
  * @param {any} value the value to be parsed
1344
- * @return {VasFieldDtoValue} the parsed value
1353
+ * @return {FieldValueType} the parsed value
1345
1354
  */
1346
1355
  parseMaybeJson(value) {
1347
1356
  if (typeof value !== 'string') {
@@ -2250,7 +2259,7 @@ class VasFormModel extends VasRestrictedAccountObjectModel {
2250
2259
  }
2251
2260
  /**
2252
2261
  * @param {VasJobModel} jobModel
2253
- * @return {Array<{id: string, value: VasFieldDtoValue}>}
2262
+ * @return {Array<{id: string, value: FieldValueType}>}
2254
2263
  */
2255
2264
  getValuesByControlId(jobModel) {
2256
2265
  const items = [];
@@ -3263,7 +3272,7 @@ class VasJobTypeModel extends VasAccountObjectModel {
3263
3272
  *
3264
3273
  * will return "value"
3265
3274
  * @param {string[]} path
3266
- * @param {Record<string, VasFieldDtoValue>} object
3275
+ * @param {Record<string, FieldValueType>} object
3267
3276
  * @return {T | undefined}
3268
3277
  */
3269
3278
  const getValueByPath = (path, object) => {
@@ -3325,10 +3334,33 @@ const getEmptyGeoLocation = () => ({
3325
3334
  timestamp: ''
3326
3335
  });
3327
3336
 
3328
- const isArrayString = (value) => {
3329
- return Array.isArray(value) && value.every(i => typeof i === 'string');
3337
+ /**
3338
+ * Try to parse the value as JSON if it looks like a JSON encoded string
3339
+ * @param value
3340
+ */
3341
+ const tryJson = (value) => {
3342
+ if (typeof value === 'string' && ['{', '['].includes(value.substring(0, 1))) {
3343
+ try {
3344
+ return JSON.parse(value);
3345
+ }
3346
+ catch (e) {
3347
+ return value;
3348
+ }
3349
+ }
3350
+ return value;
3330
3351
  };
3331
3352
 
3353
+ function isPlainObject(value) {
3354
+ return typeof value === 'object' && value !== null && !Array.isArray(value);
3355
+ }
3356
+
3357
+ let jobStaticProps;
3358
+ function getJobStaticProperties() {
3359
+ if (jobStaticProps) {
3360
+ return jobStaticProps;
3361
+ }
3362
+ return jobStaticProps = new Set(Object.getOwnPropertyNames(VasJobModel.empty()));
3363
+ }
3332
3364
  /**
3333
3365
  * JobModel
3334
3366
  */
@@ -3354,8 +3386,6 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3354
3386
  pendingFields;
3355
3387
  childModified;
3356
3388
  version;
3357
- createdByDisplayName;
3358
- modifiedByDisplayName;
3359
3389
  geoLocation;
3360
3390
  files;
3361
3391
  fields;
@@ -3364,7 +3394,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3364
3394
  reports;
3365
3395
  tasks;
3366
3396
  instruction;
3367
- 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) {
3397
+ 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) {
3368
3398
  super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, createdByName, modifiedByName, account, accessGroup);
3369
3399
  this.id = id;
3370
3400
  this.created = created;
@@ -3387,8 +3417,6 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3387
3417
  this.pendingFields = pendingFields;
3388
3418
  this.childModified = childModified;
3389
3419
  this.version = version;
3390
- this.createdByDisplayName = createdByDisplayName;
3391
- this.modifiedByDisplayName = modifiedByDisplayName;
3392
3420
  this.geoLocation = geoLocation;
3393
3421
  this.files = files;
3394
3422
  this.fields = fields;
@@ -3398,102 +3426,62 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3398
3426
  this.tasks = tasks;
3399
3427
  this.instruction = instruction;
3400
3428
  }
3401
- /**
3402
- * Returns this with the dynamic interface
3403
- * @return {VasJobModelDynamicInterface}
3404
- */
3405
- get $this() {
3406
- return this;
3429
+ get createdByDisplayName() {
3430
+ return this.createdByName;
3407
3431
  }
3408
- /**
3409
- * Returns a list of Job dynamic properties i.e. those that are added by the
3410
- * dynamic forms
3411
- */
3412
- get dynamicProperties() {
3413
- const nativeProps = this.staticProperties;
3414
- return Object
3415
- .getOwnPropertyNames(this)
3416
- .filter(prop => !nativeProps.includes(prop));
3432
+ get modifiedByDisplayName() {
3433
+ return this.modifiedByName;
3417
3434
  }
3418
3435
  /**
3419
- * Returns the list of properties of the Job type
3436
+ * Return the list of Job properties
3420
3437
  */
3421
3438
  get staticProperties() {
3422
- return Object.getOwnPropertyNames(VasJobModel.empty());
3439
+ if (jobStaticProps) {
3440
+ return jobStaticProps;
3441
+ }
3442
+ return jobStaticProps = new Set(Object.getOwnPropertyNames(VasJobModel.empty()));
3423
3443
  }
3424
3444
  /**
3425
3445
  * @return {VasJobModel}
3426
3446
  */
3427
3447
  static empty() {
3428
- return new VasJobModel('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', moment().utcOffset(), 0, '', 0, '', '', getEmptyGeoLocation(), [], [], [], [], [], [], null);
3448
+ return new VasJobModel('', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', moment().utcOffset(), 0, '', 0, getEmptyGeoLocation(), [], {}, [], [], [], [], null);
3429
3449
  }
3430
3450
  static fromDto(dto) {
3431
- 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);
3432
- const emptyKeys = model.staticProperties;
3433
- Object
3434
- .keys(dto)
3435
- .filter(key => emptyKeys.indexOf(key) === -1)
3436
- .forEach((key) => model.$this[key] = dto[key]);
3437
- return model;
3438
- }
3439
- /**
3440
- * This method will instantiate a new JobModel. The difference with this
3441
- * method of instantiation is that we are coming from a relation frame i.e.
3442
- * the job has a list of {@link VasFieldDto} instead of a Job document.
3443
- *
3444
- */
3445
- static fromRelational(dto, form) {
3446
- 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);
3447
- form.groups
3448
- .forEach(group => {
3449
- group.controls
3450
- .forEach(control => {
3451
- const field = dto.fields?.find(f => f.control === control.id);
3452
- if (!field) {
3453
- return;
3454
- }
3455
- model.getGroup(group.name)[control.name] = field.value;
3456
- });
3457
- });
3458
- return model;
3459
- }
3460
- /**
3461
- * @param {VasFormModel} formModel
3462
- * @return {Record<string, VasFieldDtoValue>}
3463
- */
3464
- getFields(formModel) {
3465
- const fields = {};
3466
- formModel.groups
3467
- .forEach(group => {
3468
- group.controls.forEach(control => {
3469
- (fields)[control.reportTemplateName] =
3470
- this.getValueByPath([group.name, control.name]) || null;
3471
- });
3451
+ // we have changed the job model and stopped using the dynamic properties
3452
+ // from form group names to hold fields. Instead, we store a simple object
3453
+ // where the control name (minus the "fields." prefix) is the key, and the
3454
+ // field value is the value. However, we have to cater for data that may
3455
+ // be persisted in the old structure, or an API response where fields is an
3456
+ // array of VasFieldDto.
3457
+ // 1: if dto.fields is already an object, we use the existing value
3458
+ const fields = isPlainObject(dto.fields) ?
3459
+ dto.fields :
3460
+ {};
3461
+ // 2: if dto.fields is an array, we're handling a vas-rest response, we
3462
+ // iterate over the fields and update the fields object.
3463
+ Array.isArray(dto.fields) && dto.fields.forEach((field) => {
3464
+ fields[field.controlName.replace('fields.', '')] = tryJson(field.value);
3472
3465
  });
3473
- return fields;
3474
- }
3475
- /**
3476
- * Will return an object whose keys are the names of all fields in the job.
3477
- * This method is similar to `getFields` except that this method will only
3478
- * return values where a value was set, as opposed to `getFields` which will
3479
- * return a value for every control even if no value was set, because it uses
3480
- * the form to drive the logic. Note also this method will return values for
3481
- * any Fields in the fields array.
3482
- * @return {Record<string, VasFieldDtoValue>}
3483
- */
3484
- getFields2() {
3485
- let fields = {};
3486
- this.dynamicProperties
3487
- .forEach((groupName) => {
3466
+ // 3: if `fields` still has no keys, we're restoring a VasJobDto object that
3467
+ // was saved in the old "form-group" style, where dynamic keys are
3468
+ // derived from the form-group names. We'll iterate over those keys, and
3469
+ // update the `fields` object. Once this model is serialized back to a
3470
+ // dto, it will have the new shape.
3471
+ if (Object.keys(fields).length === 0) {
3488
3472
  Object
3489
- .keys(this.$this[groupName])
3490
- .forEach(controlName => {
3491
- fields[controlName] =
3492
- this.getValueByPath([groupName, controlName]) || null;
3473
+ .keys(dto)
3474
+ .filter(key => !getJobStaticProperties().has(key))
3475
+ .forEach(groupName => {
3476
+ Object
3477
+ .keys(dto[groupName])
3478
+ .forEach(controlName => {
3479
+ const cn = controlName.replace('fields.', '');
3480
+ fields[cn] = dto[groupName][cn];
3481
+ });
3493
3482
  });
3494
- }, {});
3495
- this.fields.forEach(field => fields[field.controlName] = field.value);
3496
- return fields;
3483
+ }
3484
+ 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 || moment().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.geoLocation || getEmptyGeoLocation(), dto.files || [], fields, dto.jobEmails || [], dto.notes || [], dto.reports || [], dto.tasks || [], dto.instruction || null);
3497
3485
  }
3498
3486
  /**
3499
3487
  * Returns an object describing how many attachments were added to this job
@@ -3503,22 +3491,12 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3503
3491
  * job was created
3504
3492
  */
3505
3493
  getFilesUploadStatus(formModel) {
3506
- const pathsWithValue = formModel
3507
- .getCameraControlPaths()
3508
- .map(path => {
3509
- const value = this.getValueByPath(path);
3510
- if (value && !!value.id) {
3511
- return path;
3512
- }
3513
- return null;
3514
- })
3515
- .filter(path => path !== null ? path : null)
3516
- .filter(isArrayString);
3517
- let total = pathsWithValue.length;
3518
- total += this.files.length;
3494
+ const cameraFieldValues = Object
3495
+ .values(this.fields)
3496
+ .filter(value => isCameraControlValueV2(value) || isCameraControlValueV1(value));
3497
+ let total = cameraFieldValues.length + this.files.length;
3519
3498
  // calculate the number of camera images still to upload
3520
- let pending = pathsWithValue
3521
- .map(path => this.getValueByPath(path))
3499
+ let pending = cameraFieldValues
3522
3500
  .map((value) => {
3523
3501
  if (isFileDto(value)) {
3524
3502
  return value.id && value.status !== 'COMPLETE';
@@ -3531,218 +3509,51 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3531
3509
  })
3532
3510
  .filter(hasUploaded => hasUploaded)
3533
3511
  .length;
3534
- // add total from files that are pending
3535
- pending += this.files
3536
- .filter(value => value.status !== 'COMPLETE')
3537
- .length;
3512
+ // add count of job.files that are complete
3513
+ pending += this.files.filter(value => value.status !== 'COMPLETE').length;
3538
3514
  return {
3539
3515
  pending,
3540
3516
  total
3541
3517
  };
3542
3518
  }
3543
- /**
3544
- * This method will return the dynamic property from the JobModel that
3545
- * represent a group (from a form).
3546
- *
3547
- * @param name the name of the group
3548
- * @param init if true (default) and group is not found, initialise an empty
3549
- * group, otherwise throw an error
3550
- */
3551
- getGroup(name, init = true) {
3552
- let prop;
3553
- if (this.staticProperties.includes(name)) {
3554
- throw Error(`invalid group name ${name}, not a dynamic property`);
3555
- }
3556
- else if (this.$this[name] === undefined) {
3557
- if (init) {
3558
- prop = this.$this[name] = {};
3559
- }
3560
- else {
3561
- throw Error(`invalid group name ${name}, not found`);
3562
- }
3563
- }
3564
- else {
3565
- prop = this.$this[name];
3566
- if (typeof prop !== 'object') {
3567
- throw Error(`invalid group name ${name}, not an object`);
3568
- }
3569
- }
3570
- return prop;
3571
- }
3572
3519
  /**
3573
3520
  * @param path path segments
3574
3521
  */
3575
3522
  getValueByPath(path = []) {
3576
- return getValueByPath(path, this.$this);
3523
+ return getValueByPath(Array.isArray(path) ? path : path.split('.'), this);
3577
3524
  }
3578
- /**
3579
- * In order to understand why we need this method it is important to
3580
- * understand that within the system, Jobs can be represented in one of two
3581
- * ways, document and relational.
3582
- *
3583
- * The important distinction is how values submitted by a form are stored.
3584
- *
3585
- * Jobs stored as documents (JSON objects) will store user values, as dynamic
3586
- * properties of the document.
3587
- *
3588
- * Whereas, Jobs stored as relational, will store user values in an array of
3589
- * {@link VasFieldDto} objects.
3590
- *
3591
- * Depending on where we are in the system, either one of these approaches can
3592
- * be more useful than the other.
3593
- *
3594
- * This method, assumes that the JobModel has been instantiated from a
3595
- * document representation, and serves to hydrate the fields array. In order
3596
- * to achieve this, knowledge of the {@link VasFormDto} that created the job
3597
- * is required.
3598
- *
3599
- *
3600
- * Job in document representation
3601
- * {
3602
- * id: <guid>,
3603
- * reference: "something"
3604
- * <other static job properties>...
3605
- * foo: {
3606
- * bar: "value"
3607
- * }
3608
- * }
3609
- *
3610
- * Job in relational representation
3611
- * {
3612
- * id: <guid>,
3613
- * reference: "something"
3614
- * <other static job properties>...
3615
- * <will not have dynamic properties>...
3616
- * fields: [
3617
- * {
3618
- * id: <guid>,
3619
- * <other field properties>,
3620
- * value: "value"
3621
- * }
3622
- * ]
3623
- * }
3624
- *
3625
- *
3626
- * @param formModel the VasFormModel that was used to create the job
3627
- * @param controlFieldIdMap This is used to determine the id each field.
3628
- * Either one will be found in the map, or a new one is generated.
3629
- * @param controlNames if a value is provided, it will be used
3630
- * to filter the fields that are returned.
3631
- * @return {Array<VasFieldDto>}
3632
- */
3633
- hydrateFields(formModel, controlFieldIdMap = new Map(), controlNames) {
3634
- const fields = [];
3635
- formModel.groups
3636
- .forEach(group => {
3637
- group.controls.forEach(control => {
3638
- if (!control.name.startsWith('fields.')) {
3639
- return;
3640
- }
3641
- if (controlNames && !controlNames.includes(control.name)) {
3642
- return;
3643
- }
3644
- fields.push(VasFieldModel.fromDto({
3645
- // if the controlId exists in the map, use the associated fieldId,
3646
- // otherwise generate a new id for the field.
3647
- id: controlFieldIdMap.get(control.id) || UUID.UUID(),
3648
- account: this.account,
3649
- job: this.id,
3650
- createdBy: this.createdBy,
3651
- created: this.created,
3652
- modifiedBy: this.modifiedBy,
3653
- modified: this.modified,
3654
- control: control.id,
3655
- value: this.getValueByPath([group.name, control.name])
3656
- }));
3657
- });
3658
- });
3659
- this.fields = fields;
3660
- }
3661
- /**
3662
- * A very non sophisticated way to set values in the job via paths
3663
- *
3664
- * For example:
3665
- *
3666
- * setValueByPath('value', ['foo', 'bar']);
3667
- *
3668
- * will make results in job
3669
- * {
3670
- * foo: {
3671
- * bar: 'value'
3672
- * }
3673
- * }
3674
- *
3675
- * @param value the value to set
3676
- * @param path path segments
3677
- */
3678
- setValueByPath(value, path = []) {
3679
- switch (path.length) {
3680
- case 0: {
3681
- return;
3682
- }
3683
- case 1: {
3684
- this[path[0]] = value;
3685
- return;
3686
- }
3687
- case 2: {
3688
- // eslint-disable-next-line max-len
3689
- this.$this[path[0]][path[1]] = value;
3690
- return;
3691
- }
3692
- case 3: {
3693
- // eslint-disable-next-line max-len
3694
- this.$this[path[0]][path[1]][path[2]] = value;
3695
- return;
3696
- }
3697
- default: {
3698
- throw Error('path has too many segments');
3699
- }
3700
- }
3701
- }
3702
- /**
3703
- * @param staticOnly if true, will only output values for the static
3704
- * properties in the dto
3705
- */
3706
- toDto(staticOnly = false) {
3707
- if (staticOnly) {
3708
- return {
3709
- id: this.id,
3710
- created: this.created,
3711
- createdBy: this.createdBy,
3712
- modified: this.modified,
3713
- modifiedBy: this.modifiedBy,
3714
- serverCreated: this.serverCreated,
3715
- serverModified: this.serverModified,
3716
- createdByName: this.createdByName,
3717
- modifiedByName: this.modifiedByName,
3718
- account: this.account,
3719
- accessGroup: this.accessGroup,
3720
- reference: this.reference,
3721
- jobDate: this.jobDate,
3722
- jobStatus: this.jobStatus,
3723
- jobType: this.jobType,
3724
- assigneeId: this.assigneeId,
3725
- formId: this.formId,
3726
- timeZoneOffset: this.timeZoneOffset,
3727
- pendingFields: this.pendingFields,
3728
- childModified: this.childModified,
3729
- version: this.version,
3730
- createdByDisplayName: this.createdByDisplayName,
3731
- modifiedByDisplayName: this.modifiedByDisplayName,
3732
- geoLocation: this.geoLocation,
3733
- files: this.files,
3734
- fields: this.fields,
3735
- jobEmails: this.jobEmails,
3736
- notes: this.notes,
3737
- reports: this.reports,
3738
- tasks: this.tasks,
3739
- instruction: this.instruction
3740
- };
3741
- }
3742
- const dto = {};
3743
- [...this.staticProperties, ...this.dynamicProperties]
3744
- .forEach(prop => dto[prop] = this.$this[prop]);
3745
- return dto;
3525
+ toDto() {
3526
+ return {
3527
+ id: this.id,
3528
+ created: this.created,
3529
+ createdBy: this.createdBy,
3530
+ modified: this.modified,
3531
+ modifiedBy: this.modifiedBy,
3532
+ serverCreated: this.serverCreated,
3533
+ serverModified: this.serverModified,
3534
+ createdByName: this.createdByName,
3535
+ modifiedByName: this.modifiedByName,
3536
+ account: this.account,
3537
+ accessGroup: this.accessGroup,
3538
+ reference: this.reference,
3539
+ jobDate: this.jobDate,
3540
+ jobStatus: this.jobStatus,
3541
+ jobType: this.jobType,
3542
+ assigneeId: this.assigneeId,
3543
+ formId: this.formId,
3544
+ timeZoneOffset: this.timeZoneOffset,
3545
+ pendingFields: this.pendingFields,
3546
+ childModified: this.childModified,
3547
+ version: this.version,
3548
+ geoLocation: this.geoLocation,
3549
+ files: this.files,
3550
+ fields: this.fields,
3551
+ jobEmails: this.jobEmails,
3552
+ notes: this.notes,
3553
+ reports: this.reports,
3554
+ tasks: this.tasks,
3555
+ instruction: this.instruction
3556
+ };
3746
3557
  }
3747
3558
  /**
3748
3559
  * This method will parse a syntax that allows us to build strings from the
@@ -3776,7 +3587,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3776
3587
  if (!value || typeof value !== 'string') {
3777
3588
  return '';
3778
3589
  }
3779
- const fields = this.getFields2();
3590
+ const fields = this.fields;
3780
3591
  return value.replace(/({[^}]*})/g, (match, token) => {
3781
3592
  const syntax = token.substring(1, token.length - 1);
3782
3593
  let [key, filter] = syntax.split('|');
@@ -3802,24 +3613,11 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3802
3613
  if (objectKey === 'job') {
3803
3614
  result = (this.getValueByPath(path) || '').toString();
3804
3615
  }
3805
- else if (objectKey === 'fields') {
3806
- result = (getValueByPath(['fields.' + path.shift(), ...path], fields) || '').toString();
3616
+ else if (objectKey === 'fields' || this.fields[path[0]] !== undefined) {
3617
+ result = (getValueByPath(path, fields) || '').toString();
3807
3618
  }
3808
- else if (objectKey.length) {
3809
- if (options.objects) {
3810
- if (options.objects[objectKey] === undefined) {
3811
- console.debug(`objectKey ${objectKey} is not present in options.object`);
3812
- result = '';
3813
- }
3814
- else {
3815
- result = (getValueByPath(path, options.objects[objectKey]) || '')
3816
- .toString();
3817
- }
3818
- }
3819
- else {
3820
- console.debug(`objectKey ${objectKey} was used but options.object is not set`);
3821
- return '';
3822
- }
3619
+ else if (objectKey.length && options.objects && options.objects[objectKey] !== undefined) {
3620
+ result = (getValueByPath(path, options.objects[objectKey]) || '').toString();
3823
3621
  }
3824
3622
  else {
3825
3623
  return '';
@@ -3874,7 +3672,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
3874
3672
  'assigneeId',
3875
3673
  'timeZoneOffset',
3876
3674
  'pendingFields',
3877
- 'lastForm'
3675
+ 'formId'
3878
3676
  ]);
3879
3677
  }
3880
3678
  }
@@ -4486,5 +4284,5 @@ class VasVehicleModel extends VasAccountObjectModel {
4486
4284
  * Generated bundle index. Do not edit.
4487
4285
  */
4488
4286
 
4489
- export { VasAccessGroupModel, VasAccountIndexingMode, VasAccountObjectModel, VasBaseModel, VasBranchModel, VasContactModel, VasContactTypeModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFieldModel, VasFileModel, VasFireUserModel, VasFormConfigModel, VasFormModel, VasGroupModel, VasInstructionJobFieldModel, VasInstructionJobModel, VasInstructionModel, VasInstructionProviderModel, VasInvitationModel, VasInvitationTypeEnum, VasJobActionControlsStepModel, VasJobActionEmailFormStepModel, VasJobActionInstructionStepModel, VasJobActionModel, VasJobActionNotePromptStepModel, VasJobActionSetDatetimeStepModel, VasJobActionSetJobStatusStepModel, VasJobActionSetValueStepModel, VasJobActionWebhookStepModel, VasJobCopyModel, VasJobDataModel, VasJobEmailModel, VasJobModel, VasJobStatusModel, VasJobTypeModel, VasLookupModel, VasLookupTypeModel, VasMembershipModel, VasNoteModel, VasReportLayoutModel, VasReportModel, VasReportRequestModel, VasRestrictedAccountObjectModel, VasTaskModel, VasTaskTypeModel, VasUserModel, VasVehicleModel, getEmptyGeoLocation, isCameraControlValueV1, isFileDto, isJobAutomationStep, isJobControlsStep, isJobEmailFormStep, isJobInstructionStep, isJobNotePromptStep, isJobSetDatetimeStep, isJobSetJobStatusStep, isJobSetValueStep, isJobWebhookStep, prepareFieldApiValue, stepModelFactory };
4287
+ export { VasAccessGroupModel, VasAccountIndexingMode, VasAccountObjectModel, VasBaseModel, VasBranchModel, VasContactModel, VasContactTypeModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFieldModel, VasFileModel, VasFireUserModel, VasFormConfigModel, VasFormModel, VasGroupModel, VasInstructionJobFieldModel, VasInstructionJobModel, VasInstructionModel, VasInstructionProviderModel, VasInvitationModel, VasInvitationTypeEnum, VasJobActionControlsStepModel, VasJobActionEmailFormStepModel, VasJobActionInstructionStepModel, VasJobActionModel, VasJobActionNotePromptStepModel, VasJobActionSetDatetimeStepModel, VasJobActionSetJobStatusStepModel, VasJobActionSetValueStepModel, VasJobActionWebhookStepModel, VasJobCopyModel, VasJobDataModel, VasJobEmailModel, VasJobModel, VasJobStatusModel, VasJobTypeModel, VasLookupModel, VasLookupTypeModel, VasMembershipModel, VasNoteModel, VasReportLayoutModel, VasReportModel, VasReportRequestModel, VasRestrictedAccountObjectModel, VasTaskModel, VasTaskTypeModel, VasUserModel, VasVehicleModel, getEmptyGeoLocation, isCameraControlValueV1, isCameraControlValueV2, isFileDto, isJobAutomationStep, isJobControlsStep, isJobEmailFormStep, isJobInstructionStep, isJobNotePromptStep, isJobSetDatetimeStep, isJobSetJobStatusStep, isJobSetValueStep, isJobWebhookStep, prepareFieldApiValue, stepModelFactory };
4490
4288
  //# sourceMappingURL=ironcode-vas-lib.mjs.map