@ironcode/vas-lib 0.0.11 → 0.0.14

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 (103) hide show
  1. package/cjs/lib/entity/index.d.ts +6 -0
  2. package/cjs/lib/entity/index.d.ts.map +1 -1
  3. package/cjs/lib/entity/index.js +6 -0
  4. package/cjs/lib/entity/index.js.map +1 -1
  5. package/cjs/lib/entity/vas-account-config.dto.d.ts +8 -0
  6. package/cjs/lib/entity/vas-account-config.dto.d.ts.map +1 -0
  7. package/cjs/lib/entity/vas-account-config.dto.js +3 -0
  8. package/cjs/lib/entity/vas-account-config.dto.js.map +1 -0
  9. package/cjs/lib/entity/vas-account-object.model.d.ts +1 -0
  10. package/cjs/lib/entity/vas-account-object.model.d.ts.map +1 -1
  11. package/cjs/lib/entity/vas-account-object.model.js +7 -0
  12. package/cjs/lib/entity/vas-account-object.model.js.map +1 -1
  13. package/cjs/lib/entity/vas-field.dto.d.ts +1 -1
  14. package/cjs/lib/entity/vas-field.dto.js.map +1 -1
  15. package/cjs/lib/entity/vas-field.model.d.ts +44 -0
  16. package/cjs/lib/entity/vas-field.model.d.ts.map +1 -0
  17. package/cjs/lib/entity/vas-field.model.js +88 -0
  18. package/cjs/lib/entity/vas-field.model.js.map +1 -0
  19. package/cjs/lib/entity/vas-file.dto.d.ts +11 -7
  20. package/cjs/lib/entity/vas-file.dto.d.ts.map +1 -1
  21. package/cjs/lib/entity/vas-file.dto.js.map +1 -1
  22. package/cjs/lib/entity/vas-file.model.d.ts +37 -0
  23. package/cjs/lib/entity/vas-file.model.d.ts.map +1 -0
  24. package/cjs/lib/entity/vas-file.model.js +102 -0
  25. package/cjs/lib/entity/vas-file.model.js.map +1 -0
  26. package/cjs/lib/entity/vas-form-config.dto.d.ts +9 -0
  27. package/cjs/lib/entity/vas-form-config.dto.d.ts.map +1 -0
  28. package/cjs/lib/entity/vas-form-config.dto.js +3 -0
  29. package/cjs/lib/entity/vas-form-config.dto.js.map +1 -0
  30. package/cjs/lib/entity/vas-form.dto.d.ts +1 -0
  31. package/cjs/lib/entity/vas-form.dto.d.ts.map +1 -1
  32. package/cjs/lib/entity/vas-form.dto.js.map +1 -1
  33. package/cjs/lib/entity/vas-form.model.d.ts +8 -6
  34. package/cjs/lib/entity/vas-form.model.d.ts.map +1 -1
  35. package/cjs/lib/entity/vas-form.model.js +10 -7
  36. package/cjs/lib/entity/vas-form.model.js.map +1 -1
  37. package/cjs/lib/entity/vas-group.model.d.ts.map +1 -1
  38. package/cjs/lib/entity/vas-group.model.js +1 -0
  39. package/cjs/lib/entity/vas-group.model.js.map +1 -1
  40. package/cjs/lib/entity/vas-job-data.model.d.ts +28 -0
  41. package/cjs/lib/entity/vas-job-data.model.d.ts.map +1 -0
  42. package/cjs/lib/entity/vas-job-data.model.js +34 -0
  43. package/cjs/lib/entity/vas-job-data.model.js.map +1 -0
  44. package/cjs/lib/entity/vas-job.dto.d.ts +8 -2
  45. package/cjs/lib/entity/vas-job.dto.d.ts.map +1 -1
  46. package/cjs/lib/entity/vas-job.dto.js.map +1 -1
  47. package/cjs/lib/entity/vas-job.model.d.ts +105 -10
  48. package/cjs/lib/entity/vas-job.model.d.ts.map +1 -1
  49. package/cjs/lib/entity/vas-job.model.js +139 -9
  50. package/cjs/lib/entity/vas-job.model.js.map +1 -1
  51. package/cjs/lib/entity/vas-job.model.spec-data.d.ts.map +1 -1
  52. package/cjs/lib/entity/vas-job.model.spec-data.js +1 -0
  53. package/cjs/lib/entity/vas-job.model.spec-data.js.map +1 -1
  54. package/cjs/lib/entity/vas-report-layout.model.d.ts +18 -0
  55. package/cjs/lib/entity/vas-report-layout.model.d.ts.map +1 -0
  56. package/cjs/lib/entity/vas-report-layout.model.js +24 -0
  57. package/cjs/lib/entity/vas-report-layout.model.js.map +1 -0
  58. package/cjs/lib/entity/vas-report-request.dto.d.ts +1 -0
  59. package/cjs/lib/entity/vas-report-request.dto.d.ts.map +1 -1
  60. package/cjs/lib/entity/vas-report-request.dto.js.map +1 -1
  61. package/cjs/lib/entity/vas-report-request.model.d.ts +2 -1
  62. package/cjs/lib/entity/vas-report-request.model.d.ts.map +1 -1
  63. package/cjs/lib/entity/vas-report-request.model.js +5 -3
  64. package/cjs/lib/entity/vas-report-request.model.js.map +1 -1
  65. package/cjs/package.json +1 -0
  66. package/esm2020/lib/entity/index.mjs +7 -1
  67. package/esm2020/lib/entity/vas-account-config.dto.mjs +2 -0
  68. package/esm2020/lib/entity/vas-account-object.model.mjs +8 -1
  69. package/esm2020/lib/entity/vas-field.dto.mjs +1 -1
  70. package/esm2020/lib/entity/vas-field.model.mjs +88 -0
  71. package/esm2020/lib/entity/vas-file.dto.mjs +1 -1
  72. package/esm2020/lib/entity/vas-file.model.mjs +104 -0
  73. package/esm2020/lib/entity/vas-form-config.dto.mjs +2 -0
  74. package/esm2020/lib/entity/vas-form.dto.mjs +1 -1
  75. package/esm2020/lib/entity/vas-form.model.mjs +11 -8
  76. package/esm2020/lib/entity/vas-group.model.mjs +2 -1
  77. package/esm2020/lib/entity/vas-job-data.model.mjs +30 -0
  78. package/esm2020/lib/entity/vas-job.dto.mjs +1 -1
  79. package/esm2020/lib/entity/vas-job.model.mjs +150 -10
  80. package/esm2020/lib/entity/vas-report-layout.model.mjs +20 -0
  81. package/esm2020/lib/entity/vas-report-request.dto.mjs +1 -1
  82. package/esm2020/lib/entity/vas-report-request.model.mjs +6 -4
  83. package/fesm2015/ironcode-vas-lib.mjs +385 -17
  84. package/fesm2015/ironcode-vas-lib.mjs.map +1 -1
  85. package/fesm2020/ironcode-vas-lib.mjs +405 -17
  86. package/fesm2020/ironcode-vas-lib.mjs.map +1 -1
  87. package/lib/entity/index.d.ts +6 -0
  88. package/lib/entity/vas-account-config.dto.d.ts +7 -0
  89. package/lib/entity/vas-account-object.model.d.ts +1 -0
  90. package/lib/entity/vas-field.dto.d.ts +1 -1
  91. package/lib/entity/vas-field.model.d.ts +43 -0
  92. package/lib/entity/vas-file.dto.d.ts +11 -7
  93. package/lib/entity/vas-file.model.d.ts +36 -0
  94. package/lib/entity/vas-form-config.dto.d.ts +8 -0
  95. package/lib/entity/vas-form.dto.d.ts +1 -0
  96. package/lib/entity/vas-form.model.d.ts +8 -6
  97. package/lib/entity/vas-job-data.model.d.ts +27 -0
  98. package/lib/entity/vas-job.dto.d.ts +8 -2
  99. package/lib/entity/vas-job.model.d.ts +105 -10
  100. package/lib/entity/vas-report-layout.model.d.ts +17 -0
  101. package/lib/entity/vas-report-request.dto.d.ts +1 -0
  102. package/lib/entity/vas-report-request.model.d.ts +2 -1
  103. package/package.json +3 -3
@@ -45,6 +45,13 @@ class VasAccountObjectModel extends VasBaseModel {
45
45
  this.modifiedBy = modifiedBy;
46
46
  this.account = account;
47
47
  }
48
+ toApiDto() {
49
+ return {
50
+ id: this.id,
51
+ created: this.created,
52
+ modified: this.modified
53
+ };
54
+ }
48
55
  }
49
56
 
50
57
  class VasRestrictedAccountObjectModel extends VasAccountObjectModel {
@@ -367,6 +374,223 @@ class VasControlTypeModel extends VasBaseModel {
367
374
  }
368
375
  }
369
376
 
377
+ /**
378
+ * VasJobDataModel
379
+ */
380
+ class VasJobDataModel extends VasAccountObjectModel {
381
+ /**
382
+ * @param {string} id
383
+ * @param {string} created
384
+ * @param {string} serverCreated
385
+ * @param {string} createdBy
386
+ * @param {string} modified
387
+ * @param {string} serverModified
388
+ * @param {string} modifiedBy
389
+ * @param {string} account
390
+ * @param {string} job
391
+ */
392
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, job) {
393
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account);
394
+ this.id = id;
395
+ this.created = created;
396
+ this.serverCreated = serverCreated;
397
+ this.createdBy = createdBy;
398
+ this.modified = modified;
399
+ this.serverModified = serverModified;
400
+ this.modifiedBy = modifiedBy;
401
+ this.account = account;
402
+ this.job = job;
403
+ }
404
+ }
405
+
406
+ /**
407
+ * VasFieldModel
408
+ */
409
+ class VasFieldModel extends VasJobDataModel {
410
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, job, control, fieldJobPointers, value, version) {
411
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, job);
412
+ this.id = id;
413
+ this.created = created;
414
+ this.serverCreated = serverCreated;
415
+ this.createdBy = createdBy;
416
+ this.modified = modified;
417
+ this.serverModified = serverModified;
418
+ this.modifiedBy = modifiedBy;
419
+ this.account = account;
420
+ this.job = job;
421
+ this.control = control;
422
+ this.fieldJobPointers = fieldJobPointers;
423
+ this.value = value;
424
+ this.version = version;
425
+ }
426
+ /**
427
+ * @param {VasFieldDto} fieldDto
428
+ * @return {VasFieldModel}
429
+ */
430
+ static fromDto(fieldDto) {
431
+ return new VasFieldModel(fieldDto.id || UUID.UUID(), fieldDto.created || '', fieldDto.serverCreated || '', fieldDto.createdBy || '', fieldDto.modified || '', fieldDto.serverModified || '', fieldDto.modifiedBy || '', fieldDto.account || '', fieldDto.job || '', fieldDto.control || '', fieldDto.fieldJobPointers || [], fieldDto.value || '', fieldDto.version || 0);
432
+ }
433
+ /**
434
+ * @return {VasFieldDto}
435
+ */
436
+ toDto() {
437
+ return {
438
+ id: this.id,
439
+ created: this.created,
440
+ serverCreated: this.serverCreated,
441
+ createdBy: this.createdBy,
442
+ modified: this.modified,
443
+ serverModified: this.serverModified,
444
+ modifiedBy: this.modifiedBy,
445
+ account: this.account,
446
+ job: this.job,
447
+ control: this.control,
448
+ fieldJobPointers: this.fieldJobPointers,
449
+ value: this.value,
450
+ version: this.version,
451
+ };
452
+ }
453
+ /**
454
+ * @return {object}
455
+ */
456
+ toApiDto() {
457
+ return {
458
+ ...super.toApiDto(),
459
+ control: this.control,
460
+ value: this.prepareApiValue(this.value)
461
+ };
462
+ }
463
+ /**
464
+ * Prepares the value to be sent to the API. The api will only accept strings,
465
+ * numbers and booleans, thus if we have an array or object, we need to JSON
466
+ * encode it
467
+ * @param {VasFieldDto} value
468
+ * @return {string | number | boolean}
469
+ * @protected
470
+ */
471
+ prepareApiValue(value) {
472
+ switch (typeof value) {
473
+ case 'object': {
474
+ return JSON.stringify(value);
475
+ }
476
+ case 'boolean': {
477
+ return value;
478
+ }
479
+ case 'string': {
480
+ return value;
481
+ }
482
+ case 'number': {
483
+ return value;
484
+ }
485
+ default: {
486
+ return '';
487
+ }
488
+ }
489
+ }
490
+ }
491
+
492
+ /**
493
+ * VasFileDto
494
+ */
495
+ class VasFileModel extends VasJobDataModel {
496
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, job, name, fileSize, mimeType, sequence, config, url) {
497
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, job);
498
+ this.id = id;
499
+ this.created = created;
500
+ this.serverCreated = serverCreated;
501
+ this.createdBy = createdBy;
502
+ this.modified = modified;
503
+ this.serverModified = serverModified;
504
+ this.modifiedBy = modifiedBy;
505
+ this.account = account;
506
+ this.job = job;
507
+ this.name = name;
508
+ this.fileSize = fileSize;
509
+ this.mimeType = mimeType;
510
+ this.sequence = sequence;
511
+ this.config = config;
512
+ this.url = url;
513
+ }
514
+ /**
515
+ * @param {VasFieldDto} fileDto
516
+ * @return {VasFieldModel}
517
+ */
518
+ static fromDto(fileDto) {
519
+ return new VasFileModel(fileDto.id || UUID.UUID(), fileDto.created || '', fileDto.serverCreated || '', fileDto.createdBy || '', fileDto.modified || '', fileDto.serverModified || '', fileDto.modifiedBy || '', fileDto.account || '', fileDto.job || '', fileDto.name || '', fileDto.fileSize || 0, fileDto.mimeType || '', fileDto.sequence || 0, VasFileModel.parseConfig(fileDto.config), fileDto.url || '');
520
+ }
521
+ static parseConfig(config = '') {
522
+ try {
523
+ return JSON.parse(config);
524
+ }
525
+ catch (e) {
526
+ return {
527
+ displayAs: '',
528
+ embedLink: false,
529
+ group: 'photo',
530
+ description: '',
531
+ displayedName: '',
532
+ rotation: 0
533
+ };
534
+ }
535
+ }
536
+ /**
537
+ * @return {VasFileDto}
538
+ */
539
+ toDto() {
540
+ return {
541
+ id: this.id,
542
+ created: this.created,
543
+ serverCreated: this.serverCreated,
544
+ createdBy: this.createdBy,
545
+ modified: this.modified,
546
+ serverModified: this.serverModified,
547
+ modifiedBy: this.modifiedBy,
548
+ account: this.account,
549
+ job: this.job,
550
+ name: this.name,
551
+ fileSize: this.fileSize,
552
+ mimeType: this.mimeType,
553
+ sequence: this.sequence,
554
+ config: this.stringifyConfig(this.config),
555
+ url: this.url,
556
+ };
557
+ }
558
+ stringifyConfig(config) {
559
+ if (!config) {
560
+ return JSON.stringify({
561
+ displayAs: '',
562
+ embedLink: false,
563
+ group: 'photo',
564
+ description: '',
565
+ displayedName: '',
566
+ rotation: 0
567
+ });
568
+ }
569
+ try {
570
+ return JSON.stringify(config);
571
+ }
572
+ catch (e) {
573
+ console.warn(e);
574
+ return '';
575
+ }
576
+ }
577
+ toApiDto() {
578
+ return {
579
+ ...super.toApiDto(),
580
+ name: this.name || '~',
581
+ mimeType: this.mimeType || '~',
582
+ sequence: this.safeNumber(this.sequence),
583
+ config: JSON.stringify(this.config)
584
+ };
585
+ }
586
+ safeNumber(value) {
587
+ if (!Number.isFinite(value)) {
588
+ return 0;
589
+ }
590
+ return value;
591
+ }
592
+ }
593
+
370
594
  /**
371
595
  * GroupModel
372
596
  */
@@ -422,6 +646,7 @@ class VasGroupModel extends VasBaseModel {
422
646
  return new VasGroupModel(
423
647
  // eslint-disable-next-line new-cap
424
648
  dto.id || UUID.UUID(), dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.account || '', dto.accessGroup || '', dto.name || '', dto.title || '', dto.description || '', dto.sequence || 0, dto.includeInSummary || false, dto.forms || [], dto.visibilityControl || '', dto.visibleIfEquals || '', (dto.controls || [])
649
+ .filter(control => control.name.startsWith('fields.'))
425
650
  .sort((a, b) => a.sequence - b.sequence)
426
651
  .map(c => VasControlModel.fromDto(c)), dto.scoreWeight || 1);
427
652
  }
@@ -472,7 +697,7 @@ class VasGroupModel extends VasBaseModel {
472
697
  /**
473
698
  * VasFormModel
474
699
  */
475
- class VasFormModel extends VasBaseModel {
700
+ class VasFormModel extends VasRestrictedAccountObjectModel {
476
701
  /**
477
702
  * @param {string} id
478
703
  * @param {string} created
@@ -490,9 +715,10 @@ class VasFormModel extends VasBaseModel {
490
715
  * @param {string} dynamicDescriptor
491
716
  * @param {string} indexName
492
717
  * @param {string} pipelineName
718
+ * @param {string} config
493
719
  */
494
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, jobType, title, description, groups, dynamicDescriptor, indexName, pipelineName) {
495
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy);
720
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, jobType, title, description, groups, dynamicDescriptor, indexName, pipelineName, config) {
721
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup);
496
722
  this.id = id;
497
723
  this.created = created;
498
724
  this.serverCreated = serverCreated;
@@ -509,6 +735,7 @@ class VasFormModel extends VasBaseModel {
509
735
  this.dynamicDescriptor = dynamicDescriptor;
510
736
  this.indexName = indexName;
511
737
  this.pipelineName = pipelineName;
738
+ this.config = config;
512
739
  }
513
740
  /**
514
741
  * Returns the name of this form in a "safe" way, i.e. no spaces, special
@@ -551,7 +778,7 @@ class VasFormModel extends VasBaseModel {
551
778
  static fromDto(dto) {
552
779
  return new VasFormModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.account || '', dto.accessGroup || '', dto.jobType || '', dto.title || '', dto.description || '', (dto.groups || [])
553
780
  .sort((a, b) => a.sequence - b.sequence)
554
- .map(g => VasGroupModel.fromDto(g)), dto.dynamicDescriptor || '', dto.indexName || '', dto.pipelineName || '');
781
+ .map(g => VasGroupModel.fromDto(g)), dto.dynamicDescriptor || '', dto.indexName || '', dto.pipelineName || '', dto.config || '');
555
782
  }
556
783
  addControlTypesToControl(controlTypes) {
557
784
  const controlTypeModels = controlTypes
@@ -654,7 +881,8 @@ class VasFormModel extends VasBaseModel {
654
881
  groups: this.groups.map(group => group.toDto()),
655
882
  dynamicDescriptor: this.dynamicDescriptor,
656
883
  indexName: this.indexName,
657
- pipelineName: this.pipelineName
884
+ pipelineName: this.pipelineName,
885
+ config: this.config
658
886
  };
659
887
  }
660
888
  }
@@ -726,7 +954,7 @@ const getValueByPath = (path, object) => {
726
954
  /**
727
955
  * JobModel
728
956
  */
729
- class VasJobModel extends VasBaseModel {
957
+ class VasJobModel extends VasRestrictedAccountObjectModel {
730
958
  /**
731
959
  * @param {string} id
732
960
  * @param {string} created
@@ -741,12 +969,17 @@ class VasJobModel extends VasBaseModel {
741
969
  * @param {string} jobDate
742
970
  * @param {string} jobStatus
743
971
  * @param {string} jobType
744
- * @param {string} assignee
972
+ * @param {string} assigneeId
745
973
  * @param {string} formId
746
974
  * @param {number} timeZoneOffset
975
+ * @param {number} pendingFields
976
+ * @param {string} childModified
977
+ * @param {number} version
978
+ * @param {Array<VasFieldDto>} fields
979
+ * @param {Array<VasFileDto>} files
747
980
  */
748
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, reference, jobDate, jobStatus, jobType, assignee, formId, timeZoneOffset) {
749
- super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy);
981
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, reference, jobDate, jobStatus, jobType, assigneeId, formId, timeZoneOffset, pendingFields, childModified, version, fields, files) {
982
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup);
750
983
  this.id = id;
751
984
  this.created = created;
752
985
  this.serverCreated = serverCreated;
@@ -760,9 +993,14 @@ class VasJobModel extends VasBaseModel {
760
993
  this.jobDate = jobDate;
761
994
  this.jobStatus = jobStatus;
762
995
  this.jobType = jobType;
763
- this.assignee = assignee;
996
+ this.assigneeId = assigneeId;
764
997
  this.formId = formId;
765
998
  this.timeZoneOffset = timeZoneOffset;
999
+ this.pendingFields = pendingFields;
1000
+ this.childModified = childModified;
1001
+ this.version = version;
1002
+ this.fields = fields;
1003
+ this.files = files;
766
1004
  }
767
1005
  /**
768
1006
  * Returns this with the dynamic interface
@@ -794,7 +1032,7 @@ class VasJobModel extends VasBaseModel {
794
1032
  static empty() {
795
1033
  return new VasJobModel(
796
1034
  // eslint-disable-next-line new-cap
797
- UUID.UUID(), '', '', '', '', '', '', '', '', '', '', '', '', '', '', moment().utcOffset());
1035
+ UUID.UUID(), '', '', '', '', '', '', '', '', '', '', '', '', '', '', moment().utcOffset(), 0, '', 0, [], []);
798
1036
  }
799
1037
  /**
800
1038
  * @param {VasJobDto} jobDto
@@ -803,7 +1041,7 @@ class VasJobModel extends VasBaseModel {
803
1041
  static fromDto(jobDto) {
804
1042
  const model = new VasJobModel(
805
1043
  // eslint-disable-next-line new-cap
806
- jobDto.id || UUID.UUID(), jobDto.created || '', jobDto.serverCreated || '', jobDto.createdBy || '', jobDto.modified || '', jobDto.serverModified || '', jobDto.modifiedBy || '', jobDto.account || '', jobDto.accessGroup || '', jobDto.reference || '', jobDto.jobDate || '', jobDto.jobStatus || '', jobDto.jobType || '', jobDto.assignee || '', jobDto.formId || '', jobDto.timeZoneOffset || moment().utcOffset());
1044
+ jobDto.id || UUID.UUID(), jobDto.created || '', jobDto.serverCreated || '', jobDto.createdBy || '', jobDto.modified || '', jobDto.serverModified || '', jobDto.modifiedBy || '', jobDto.account || '', jobDto.accessGroup || '', jobDto.reference || '', jobDto.jobDate || '', jobDto.jobStatus || '', jobDto.jobType || '', jobDto.assigneeId || '', jobDto.formId || '', jobDto.timeZoneOffset || moment().utcOffset(), jobDto.pendingFields || 0, jobDto.childModified || '', jobDto.version || 0, jobDto.fields || [], jobDto.files || []);
807
1045
  const emptyKeys = model.staticProperties;
808
1046
  Object
809
1047
  .keys(jobDto)
@@ -847,6 +1085,114 @@ class VasJobModel extends VasBaseModel {
847
1085
  }, {});
848
1086
  return fields;
849
1087
  }
1088
+ /**
1089
+ * This method will hydrate the `fields` property of the model. The reason for
1090
+ * this is that we have different ways to store the field data. One way, is
1091
+ * we store them as dynamic properties of the job. For example job.foo.bar,
1092
+ * where `foo` is the name of a Group, and `bar` is the name of a control.
1093
+ * Thus, when we create a job using a form in the client, the job object will
1094
+ * have its static properties (id, account, reference etc), and also a number
1095
+ * of dynamic properties determined by the Groups and Controls. This kind of
1096
+ * object is nice to work with in certain circumstances. However, the api
1097
+ * works differently. In the API a Job is a record, and references a number of
1098
+ * Field records. Each Field stores the value. Comparing these two models we
1099
+ * have:
1100
+ * A) job with dynamic properties, e.g.
1101
+ * {
1102
+ * id: <guid>,
1103
+ * reference: "something"
1104
+ * <other static job properties>...
1105
+ * foo: {
1106
+ * bar: "value"
1107
+ * }
1108
+ * }
1109
+ *
1110
+ * B) job with fields
1111
+ * {
1112
+ * id: <guid>,
1113
+ * reference: "something"
1114
+ * <other static job properties>...
1115
+ * <will not have dynamic properties>...
1116
+ * fields: [
1117
+ * {
1118
+ * id: <guid>,
1119
+ * <other field properties>,
1120
+ * value: "value"
1121
+ * }
1122
+ * ]
1123
+ * }
1124
+ *
1125
+ * So, what this method does is given a JobModel in the form of A, read all
1126
+ * of those dynamic properties and set them into `fields`. Doing this requires
1127
+ * knowledge of the Form that was used to create the job. Moreover, since the
1128
+ * dynamic properties do not contain the ids of the fields, we also allow to
1129
+ * pass in a `controlFieldIdMap`. This map stores the mapping between Control
1130
+ * and the Field that was created in the Job to store the value for that
1131
+ * Control. This is useful, if for example you want to compare a Job in form A
1132
+ * with a Job in form B, for example if you want to update the Job on the API
1133
+ * with a Job that was saved by a client in form A.
1134
+ *
1135
+ * E.g.
1136
+ * Client -> API: client requests form
1137
+ * User -> Client: user fills in the form and submits
1138
+ * Client -> Firestore: client saves the Job in form A i.e. dynamic props
1139
+ * Firestore -> Function: A function is triggered to sync the job to the API
1140
+ * Function -> API: Function checks if job already exists, it receives 404
1141
+ * Function -> Function: The function calls `hydrateFields(...)`
1142
+ * Function -> API: The function POST the Job to /jobs
1143
+ * Function -> API: The function POST each field to /fields
1144
+ *
1145
+ * Similarly, if the user updates the job
1146
+ * Client -> API: client requests form
1147
+ * User -> Client: user fills in the form and submits an update
1148
+ * Client -> Firestore: client saves the Job in form A i.e. dynamic props
1149
+ * Firestore -> Function: A function is triggered to sync the job to the API
1150
+ * Function -> API: Function checks if job already exists, it receives 200
1151
+ * Function -> Function: The function calls `hydrateFields(...)` passing in
1152
+ * the map is made by iterating over the fields it
1153
+ * received from the API and storing the mappings
1154
+ * between controlId and fieldId for each field
1155
+ * Function -> API: The function PATCH the Job to /jobs
1156
+ * Function -> API: The function POST/PATCH each field to /fields
1157
+ * treated as new
1158
+ *
1159
+ * @param {VasFormModel} formModel the VasFormModel that was used to create
1160
+ * the job
1161
+ * @param {Map<string, string>} controlFieldIdMap a mapping of control to
1162
+ * field ids. This is used to determine whether a new id for the field should
1163
+ * be generated, or to reuse an existing one from the map.
1164
+ * @param {Array<string>} controlNames if a value is provided, it will be used
1165
+ * to filter the fields that are returned.
1166
+ * @return {Array<VasFieldDto>}
1167
+ */
1168
+ hydrateFields(formModel, controlFieldIdMap = new Map(), controlNames) {
1169
+ const fields = [];
1170
+ formModel.groups
1171
+ .forEach(group => {
1172
+ group.controls.forEach(control => {
1173
+ if (!control.name.startsWith('fields.')) {
1174
+ return;
1175
+ }
1176
+ if (controlNames && !controlNames.includes(control.name)) {
1177
+ return;
1178
+ }
1179
+ fields.push(VasFieldModel.fromDto({
1180
+ // if the controlId exists in the map, use the associated fieldId,
1181
+ // otherwise generate a new id for the field.
1182
+ id: controlFieldIdMap.get(control.id) || UUID.UUID(),
1183
+ account: this.account,
1184
+ job: this.id,
1185
+ createdBy: this.createdBy,
1186
+ created: this.created,
1187
+ modifiedBy: this.modifiedBy,
1188
+ modified: this.modified,
1189
+ control: control.id,
1190
+ value: this.getValueByPath([group.name, control.name])
1191
+ }));
1192
+ });
1193
+ });
1194
+ this.fields = fields;
1195
+ }
850
1196
  /**
851
1197
 
852
1198
  * @param {string[]} path path segments
@@ -917,9 +1263,14 @@ class VasJobModel extends VasBaseModel {
917
1263
  jobDate: this.jobDate,
918
1264
  jobStatus: this.jobStatus,
919
1265
  jobType: this.jobType,
920
- assignee: this.assignee,
1266
+ assigneeId: this.assigneeId,
921
1267
  formId: this.formId,
922
1268
  timeZoneOffset: this.timeZoneOffset,
1269
+ pendingFields: this.pendingFields,
1270
+ childModified: this.childModified,
1271
+ version: this.version,
1272
+ fields: this.fields,
1273
+ files: this.files
923
1274
  };
924
1275
  }
925
1276
  const dto = {};
@@ -1022,10 +1373,45 @@ class VasJobModel extends VasBaseModel {
1022
1373
  }).trim();
1023
1374
  }
1024
1375
  ;
1376
+ /**
1377
+ * @return {object}
1378
+ */
1379
+ toApiDto() {
1380
+ return {
1381
+ ...super.toApiDto(),
1382
+ reference: this.reference || '~',
1383
+ jobDate: this.jobDate || '~',
1384
+ jobType: this.jobType || '~',
1385
+ accessGroup: this.accessGroup || '~',
1386
+ jobStatus: this.jobStatus || '~',
1387
+ assigneeId: this.assigneeId || '~',
1388
+ timeZoneOffset: this.timeZoneOffset || 0,
1389
+ pendingFields: this.pendingFields || 0,
1390
+ };
1391
+ }
1392
+ }
1393
+
1394
+ class VasReportLayoutModel extends VasRestrictedAccountObjectModel {
1395
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, jobType, title, description, entryPoint) {
1396
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup);
1397
+ this.id = id;
1398
+ this.created = created;
1399
+ this.serverCreated = serverCreated;
1400
+ this.createdBy = createdBy;
1401
+ this.modified = modified;
1402
+ this.serverModified = serverModified;
1403
+ this.modifiedBy = modifiedBy;
1404
+ this.account = account;
1405
+ this.accessGroup = accessGroup;
1406
+ this.jobType = jobType;
1407
+ this.title = title;
1408
+ this.description = description;
1409
+ this.entryPoint = entryPoint;
1410
+ }
1025
1411
  }
1026
1412
 
1027
1413
  class VasReportRequestModel extends VasBaseModel {
1028
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, error, jobId, title, url) {
1414
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, error, jobId, title, url, reportId) {
1029
1415
  super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy);
1030
1416
  this.id = id;
1031
1417
  this.created = created;
@@ -1038,9 +1424,10 @@ class VasReportRequestModel extends VasBaseModel {
1038
1424
  this.jobId = jobId;
1039
1425
  this.title = title;
1040
1426
  this.url = url;
1427
+ this.reportId = reportId;
1041
1428
  }
1042
1429
  static fromDto(dto) {
1043
- return new VasReportRequestModel(dto.id || UUID.UUID(), dto.created || moment().toISOString(), dto.serverCreated || '', dto.createdBy || '', dto.modified || moment().toISOString(), dto.serverModified || '', dto.modifiedBy || '', dto.error || '', dto.jobId || '', dto.title || '', dto.url || '');
1430
+ return new VasReportRequestModel(dto.id || UUID.UUID(), dto.created || moment().toISOString(), dto.serverCreated || '', dto.createdBy || '', dto.modified || moment().toISOString(), dto.serverModified || '', dto.modifiedBy || '', dto.error || '', dto.jobId || '', dto.title || '', dto.url || '', dto.reportId || '');
1044
1431
  }
1045
1432
  toDto() {
1046
1433
  return {
@@ -1054,7 +1441,8 @@ class VasReportRequestModel extends VasBaseModel {
1054
1441
  error: this.error,
1055
1442
  jobId: this.jobId,
1056
1443
  title: this.title,
1057
- url: this.url
1444
+ url: this.url,
1445
+ reportId: this.reportId
1058
1446
  };
1059
1447
  }
1060
1448
  }
@@ -1107,5 +1495,5 @@ class VasUserModel extends VasBaseModel {
1107
1495
  * Generated bundle index. Do not edit.
1108
1496
  */
1109
1497
 
1110
- export { VasAccountObjectModel, VasBaseModel, VasBranchModel, VasContactModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFormModel, VasGroupModel, VasJobModel, VasReportRequestModel, VasRestrictedAccountObjectModel, VasUserModel };
1498
+ export { VasAccountObjectModel, VasBaseModel, VasBranchModel, VasContactModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFieldModel, VasFileModel, VasFormModel, VasGroupModel, VasJobDataModel, VasJobModel, VasReportLayoutModel, VasReportRequestModel, VasRestrictedAccountObjectModel, VasUserModel };
1111
1499
  //# sourceMappingURL=ironcode-vas-lib.mjs.map