@ironcode/vas-lib 0.0.7 → 0.0.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 (77) hide show
  1. package/cjs/lib/entity/index.d.ts +4 -0
  2. package/cjs/lib/entity/index.d.ts.map +1 -1
  3. package/cjs/lib/entity/index.js +4 -0
  4. package/cjs/lib/entity/index.js.map +1 -1
  5. package/cjs/lib/entity/vas-account-object.model.d.ts +13 -0
  6. package/cjs/lib/entity/vas-account-object.model.d.ts.map +1 -0
  7. package/cjs/lib/entity/vas-account-object.model.js +19 -0
  8. package/cjs/lib/entity/vas-account-object.model.js.map +1 -0
  9. package/cjs/lib/entity/vas-branch.dto.d.ts +3 -3
  10. package/cjs/lib/entity/vas-branch.dto.d.ts.map +1 -1
  11. package/cjs/lib/entity/vas-branch.dto.js.map +1 -1
  12. package/cjs/lib/entity/vas-branch.model.d.ts +5 -4
  13. package/cjs/lib/entity/vas-branch.model.d.ts.map +1 -1
  14. package/cjs/lib/entity/vas-branch.model.js +9 -7
  15. package/cjs/lib/entity/vas-branch.model.js.map +1 -1
  16. package/cjs/lib/entity/vas-contact.dto.d.ts +2 -3
  17. package/cjs/lib/entity/vas-contact.dto.d.ts.map +1 -1
  18. package/cjs/lib/entity/vas-contact.dto.js.map +1 -1
  19. package/cjs/lib/entity/vas-contact.model.d.ts +23 -0
  20. package/cjs/lib/entity/vas-contact.model.d.ts.map +1 -0
  21. package/cjs/lib/entity/vas-contact.model.js +48 -0
  22. package/cjs/lib/entity/vas-contact.model.js.map +1 -0
  23. package/cjs/lib/entity/vas-control.model.d.ts +1 -1
  24. package/cjs/lib/entity/vas-control.model.js +1 -1
  25. package/cjs/lib/entity/vas-control.model.js.map +1 -1
  26. package/cjs/lib/entity/vas-form.dto.d.ts +1 -0
  27. package/cjs/lib/entity/vas-form.dto.d.ts.map +1 -1
  28. package/cjs/lib/entity/vas-form.dto.js.map +1 -1
  29. package/cjs/lib/entity/vas-form.model.d.ts +3 -1
  30. package/cjs/lib/entity/vas-form.model.d.ts.map +1 -1
  31. package/cjs/lib/entity/vas-form.model.js +5 -2
  32. package/cjs/lib/entity/vas-form.model.js.map +1 -1
  33. package/cjs/lib/entity/vas-job.model.d.ts +14 -27
  34. package/cjs/lib/entity/vas-job.model.d.ts.map +1 -1
  35. package/cjs/lib/entity/vas-job.model.js +74 -55
  36. package/cjs/lib/entity/vas-job.model.js.map +1 -1
  37. package/cjs/lib/entity/vas-job.model.spec-data.d.ts.map +1 -1
  38. package/cjs/lib/entity/vas-job.model.spec-data.js +1 -0
  39. package/cjs/lib/entity/vas-job.model.spec-data.js.map +1 -1
  40. package/cjs/lib/entity/vas-restricted-account-object.model.d.ts +14 -0
  41. package/cjs/lib/entity/vas-restricted-account-object.model.d.ts.map +1 -0
  42. package/cjs/lib/entity/vas-restricted-account-object.model.js +20 -0
  43. package/cjs/lib/entity/vas-restricted-account-object.model.js.map +1 -0
  44. package/cjs/lib/utils/get-value-by-path.d.ts +20 -0
  45. package/cjs/lib/utils/get-value-by-path.d.ts.map +1 -0
  46. package/cjs/lib/utils/get-value-by-path.js +68 -0
  47. package/cjs/lib/utils/get-value-by-path.js.map +1 -0
  48. package/cjs/package.json +1 -1
  49. package/esm2020/lib/entity/index.mjs +5 -1
  50. package/esm2020/lib/entity/vas-account-object.model.mjs +15 -0
  51. package/esm2020/lib/entity/vas-branch.dto.mjs +1 -1
  52. package/esm2020/lib/entity/vas-branch.model.mjs +64 -0
  53. package/esm2020/lib/entity/vas-contact.dto.mjs +1 -1
  54. package/esm2020/lib/entity/vas-contact.model.mjs +44 -0
  55. package/esm2020/lib/entity/vas-control.model.mjs +2 -2
  56. package/esm2020/lib/entity/vas-form.dto.mjs +1 -1
  57. package/esm2020/lib/entity/vas-form.model.mjs +6 -3
  58. package/esm2020/lib/entity/vas-job.model.mjs +75 -56
  59. package/esm2020/lib/entity/vas-restricted-account-object.model.mjs +16 -0
  60. package/esm2020/lib/utils/get-value-by-path.mjs +64 -0
  61. package/fesm2015/ironcode-vas-lib.mjs +279 -59
  62. package/fesm2015/ironcode-vas-lib.mjs.map +1 -1
  63. package/fesm2020/ironcode-vas-lib.mjs +279 -59
  64. package/fesm2020/ironcode-vas-lib.mjs.map +1 -1
  65. package/lib/entity/index.d.ts +4 -0
  66. package/lib/entity/vas-account-object.model.d.ts +12 -0
  67. package/lib/entity/vas-branch.dto.d.ts +3 -3
  68. package/lib/entity/vas-branch.model.d.ts +34 -0
  69. package/lib/entity/vas-contact.dto.d.ts +2 -3
  70. package/lib/entity/vas-contact.model.d.ts +22 -0
  71. package/lib/entity/vas-control.model.d.ts +1 -1
  72. package/lib/entity/vas-form.dto.d.ts +1 -0
  73. package/lib/entity/vas-form.model.d.ts +3 -1
  74. package/lib/entity/vas-job.model.d.ts +14 -27
  75. package/lib/entity/vas-restricted-account-object.model.d.ts +13 -0
  76. package/lib/utils/get-value-by-path.d.ts +19 -0
  77. package/package.json +1 -1
@@ -33,6 +33,141 @@ class VasBaseModel {
33
33
  }
34
34
  }
35
35
 
36
+ class VasAccountObjectModel extends VasBaseModel {
37
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account) {
38
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy);
39
+ this.id = id;
40
+ this.created = created;
41
+ this.serverCreated = serverCreated;
42
+ this.createdBy = createdBy;
43
+ this.modified = modified;
44
+ this.serverModified = serverModified;
45
+ this.modifiedBy = modifiedBy;
46
+ this.account = account;
47
+ }
48
+ }
49
+
50
+ class VasRestrictedAccountObjectModel extends VasAccountObjectModel {
51
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup) {
52
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account);
53
+ this.id = id;
54
+ this.created = created;
55
+ this.serverCreated = serverCreated;
56
+ this.createdBy = createdBy;
57
+ this.modified = modified;
58
+ this.serverModified = serverModified;
59
+ this.modifiedBy = modifiedBy;
60
+ this.account = account;
61
+ this.accessGroup = accessGroup;
62
+ }
63
+ }
64
+
65
+ class VasBranchModel extends VasRestrictedAccountObjectModel {
66
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, branchType, storeCode, address, city, postcode, email, locationManager, areaManager, regionalDirector, salesManager, cluster, hourWeekdays, hourSaturday, hourSunday, exceptions, active) {
67
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup);
68
+ this.id = id;
69
+ this.created = created;
70
+ this.serverCreated = serverCreated;
71
+ this.createdBy = createdBy;
72
+ this.modified = modified;
73
+ this.serverModified = serverModified;
74
+ this.modifiedBy = modifiedBy;
75
+ this.account = account;
76
+ this.accessGroup = accessGroup;
77
+ this.branchType = branchType;
78
+ this.storeCode = storeCode;
79
+ this.address = address;
80
+ this.city = city;
81
+ this.postcode = postcode;
82
+ this.email = email;
83
+ this.locationManager = locationManager;
84
+ this.areaManager = areaManager;
85
+ this.regionalDirector = regionalDirector;
86
+ this.salesManager = salesManager;
87
+ this.cluster = cluster;
88
+ this.hourWeekdays = hourWeekdays;
89
+ this.hourSaturday = hourSaturday;
90
+ this.hourSunday = hourSunday;
91
+ this.exceptions = exceptions;
92
+ this.active = active;
93
+ }
94
+ static fromDto(dto) {
95
+ return new VasBranchModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.account || '', dto.accessGroup || '', dto.branchType || '', dto.storeCode || '', dto.address || '', dto.city || '', dto.postcode || '', dto.email || '', dto.locationManager || undefined, dto.areaManager || undefined, dto.regionalDirector || undefined, dto.salesManager || undefined, dto.cluster || '', dto.hourWeekdays || [], dto.hourSaturday || [], dto.hourSunday || [], dto.exceptions || '', dto.active || true);
96
+ }
97
+ toDto() {
98
+ return {
99
+ id: this.id,
100
+ created: this.created,
101
+ serverCreated: this.serverCreated,
102
+ createdBy: this.createdBy,
103
+ modified: this.modified,
104
+ serverModified: this.serverModified,
105
+ modifiedBy: this.modifiedBy,
106
+ account: this.account,
107
+ accessGroup: this.accessGroup,
108
+ branchType: this.branchType,
109
+ storeCode: this.storeCode,
110
+ address: this.address,
111
+ city: this.city,
112
+ postcode: this.postcode,
113
+ email: this.email,
114
+ locationManager: this.locationManager,
115
+ areaManager: this.areaManager,
116
+ regionalDirector: this.regionalDirector,
117
+ salesManager: this.salesManager,
118
+ cluster: this.cluster,
119
+ hourWeekdays: this.hourWeekdays,
120
+ hourSaturday: this.hourSaturday,
121
+ hourSunday: this.hourSunday,
122
+ exceptions: this.exceptions,
123
+ active: this.active
124
+ };
125
+ }
126
+ }
127
+
128
+ class VasContactModel extends VasRestrictedAccountObjectModel {
129
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, contactType, name, email, mobile, phone, address) {
130
+ super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup);
131
+ this.id = id;
132
+ this.created = created;
133
+ this.serverCreated = serverCreated;
134
+ this.createdBy = createdBy;
135
+ this.modified = modified;
136
+ this.serverModified = serverModified;
137
+ this.modifiedBy = modifiedBy;
138
+ this.account = account;
139
+ this.accessGroup = accessGroup;
140
+ this.contactType = contactType;
141
+ this.name = name;
142
+ this.email = email;
143
+ this.mobile = mobile;
144
+ this.phone = phone;
145
+ this.address = address;
146
+ }
147
+ static fromDto(dto) {
148
+ return new VasContactModel(dto.id || '', dto.created || '', dto.serverCreated || '', dto.createdBy || '', dto.modified || '', dto.serverModified || '', dto.modifiedBy || '', dto.account || '', dto.accessGroup || '', dto.contactType || '', dto.name || '', dto.email || '', dto.mobile || '', dto.phone || '', dto.address || '');
149
+ }
150
+ toDto() {
151
+ return {
152
+ id: this.id,
153
+ created: this.created,
154
+ serverCreated: this.serverCreated,
155
+ createdBy: this.createdBy,
156
+ modified: this.modified,
157
+ serverModified: this.serverModified,
158
+ modifiedBy: this.modifiedBy,
159
+ account: this.account,
160
+ accessGroup: this.accessGroup,
161
+ contactType: this.contactType,
162
+ name: this.name,
163
+ email: this.email,
164
+ mobile: this.mobile,
165
+ phone: this.phone,
166
+ address: this.address,
167
+ };
168
+ }
169
+ }
170
+
36
171
  /**
37
172
  * ControlModel
38
173
  */
@@ -108,7 +243,7 @@ class VasControlModel extends VasBaseModel {
108
243
  }
109
244
  /**
110
245
  * Returns the name of this control to be used in the report templates
111
- * i.e. field.foo -> foo
246
+ * i.e. fields.foo -> foo
112
247
  * @return {string}
113
248
  */
114
249
  get reportTemplateName() {
@@ -352,8 +487,9 @@ class VasFormModel extends VasBaseModel {
352
487
  * @param {string} title
353
488
  * @param {string} description
354
489
  * @param {VasGroupModel[]} groups
490
+ * @param {string} dynamicDescriptor
355
491
  */
356
- constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, jobType, title, description, groups) {
492
+ constructor(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy, account, accessGroup, jobType, title, description, groups, dynamicDescriptor) {
357
493
  super(id, created, serverCreated, createdBy, modified, serverModified, modifiedBy);
358
494
  this.id = id;
359
495
  this.created = created;
@@ -368,6 +504,7 @@ class VasFormModel extends VasBaseModel {
368
504
  this.title = title;
369
505
  this.description = description;
370
506
  this.groups = groups;
507
+ this.dynamicDescriptor = dynamicDescriptor;
371
508
  }
372
509
  /**
373
510
  * Returns the name of this form in a "safe" way, i.e. no spaces, special
@@ -410,7 +547,7 @@ class VasFormModel extends VasBaseModel {
410
547
  static fromDto(dto) {
411
548
  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 || [])
412
549
  .sort((a, b) => a.sequence - b.sequence)
413
- .map(g => VasGroupModel.fromDto(g)));
550
+ .map(g => VasGroupModel.fromDto(g)), dto.dynamicDescriptor || '');
414
551
  }
415
552
  addControlTypesToControl(controlTypes) {
416
553
  const controlTypeModels = controlTypes
@@ -511,10 +648,75 @@ class VasFormModel extends VasBaseModel {
511
648
  title: this.title,
512
649
  description: this.description,
513
650
  groups: this.groups.map(group => group.toDto()),
651
+ dynamicDescriptor: this.dynamicDescriptor
514
652
  };
515
653
  }
516
654
  }
517
655
 
656
+ /**
657
+ * A non sophisticated way to get values from the job via paths. For example:
658
+ *
659
+ * getValueByPath(
660
+ * ['foo', 'bar'],
661
+ * {
662
+ * foo: {
663
+ * bar: 'value'
664
+ * }
665
+ * }
666
+ * );
667
+ *
668
+ * will return "value"
669
+ * @param {string[]} path
670
+ * @param {Record<string, VasFieldDtoValue>} object
671
+ * @return {T | undefined}
672
+ */
673
+ const getValueByPath = (path, object) => {
674
+ switch (path.length) {
675
+ case 0: {
676
+ return;
677
+ }
678
+ case 1: {
679
+ return (object)[path[0]];
680
+ }
681
+ case 2: {
682
+ const val0 = object[path[0]];
683
+ if (!val0) {
684
+ return undefined;
685
+ }
686
+ return val0[path[1]];
687
+ }
688
+ case 3: {
689
+ const val0 = object[path[0]];
690
+ if (!val0) {
691
+ return undefined;
692
+ }
693
+ const val1 = val0[path[1]];
694
+ if (!val1) {
695
+ return undefined;
696
+ }
697
+ return val1[path[2]];
698
+ }
699
+ case 4: {
700
+ const val0 = object[path[0]];
701
+ if (!val0) {
702
+ return undefined;
703
+ }
704
+ const val1 = val0[path[1]];
705
+ if (!val1) {
706
+ return undefined;
707
+ }
708
+ const val2 = val1[path[2]];
709
+ if (!val2) {
710
+ return undefined;
711
+ }
712
+ return val2[path[3]];
713
+ }
714
+ default: {
715
+ throw Error('path has too many segments');
716
+ }
717
+ }
718
+ };
719
+
518
720
  /**
519
721
  * JobModel
520
722
  */
@@ -561,8 +763,6 @@ class VasJobModel extends VasBaseModel {
561
763
  * @return {VasJobModelDynamicInterface}
562
764
  */
563
765
  get $this() {
564
- // eslint-disable-next-line @typescript-eslint/no-this-alias
565
- const $this = this;
566
766
  return this;
567
767
  }
568
768
  /**
@@ -621,54 +821,33 @@ class VasJobModel extends VasBaseModel {
621
821
  return fields;
622
822
  }
623
823
  /**
624
- * A very non sophisticated way to get values from the job via paths
625
- *
626
- * For example:
627
- *
628
- * getValueByPath(['foo', 'bar']);
629
- *
630
- * if job is
631
- * {
632
- * foo: {
633
- * bar: 'value'
634
- * }
635
- * }
636
- *
637
- * will return "value"
638
- *
824
+ * Will return an object whose keys are the names of all fields in the job but
825
+ * with the "fields." part removed. This method is similar to `getFields`
826
+ * except that this method will only return values that are set whereas
827
+ * `getFields` will return a property regardless (because it uses the form to
828
+ * drive the logic)
829
+ * @return {Record<string, VasFieldDtoValue>}
830
+ */
831
+ getFields2() {
832
+ let fields = {};
833
+ this.dynamicProperties
834
+ .forEach((groupName) => {
835
+ Object
836
+ .keys(this.$this[groupName])
837
+ .forEach(controlName => {
838
+ const controlNameShort = controlName.replace(/fields\./, '');
839
+ fields[controlNameShort] = this.getValueByPath([groupName, controlName]);
840
+ });
841
+ }, {});
842
+ return fields;
843
+ }
844
+ /**
845
+
639
846
  * @param {string[]} path path segments
640
847
  * @return {void}
641
848
  */
642
849
  getValueByPath(path = []) {
643
- switch (path.length) {
644
- case 0: {
645
- return;
646
- }
647
- case 1: {
648
- return (this.$this)[path[0]];
649
- }
650
- case 2: {
651
- const val0 = this.$this[path[0]];
652
- if (!val0) {
653
- return undefined;
654
- }
655
- return val0[path[1]];
656
- }
657
- case 3: {
658
- const val0 = this.$this[path[0]];
659
- if (!val0) {
660
- return undefined;
661
- }
662
- const val1 = val0[path[1]];
663
- if (!val1) {
664
- return undefined;
665
- }
666
- return val1[path[2]];
667
- }
668
- default: {
669
- throw Error('path has too many segments');
670
- }
671
- }
850
+ return getValueByPath(path, this.$this);
672
851
  }
673
852
  /**
674
853
  * A very non sophisticated way to set values in the job via paths
@@ -693,7 +872,7 @@ class VasJobModel extends VasBaseModel {
693
872
  return;
694
873
  }
695
874
  case 1: {
696
- (this.$this)[path[0]] = value;
875
+ this[path[0]] = value;
697
876
  return;
698
877
  }
699
878
  case 2: {
@@ -717,14 +896,29 @@ class VasJobModel extends VasBaseModel {
717
896
  * @return {VasJobDto}
718
897
  */
719
898
  toDto(staticOnly = false) {
720
- const dto = {};
721
- this.staticProperties
722
- .forEach(prop => (dto)[prop] = this.$this[prop]);
723
899
  if (staticOnly) {
724
- return dto;
900
+ return {
901
+ id: this.id,
902
+ created: this.created,
903
+ createdBy: this.createdBy,
904
+ modified: this.modified,
905
+ modifiedBy: this.modifiedBy,
906
+ serverCreated: this.serverCreated,
907
+ serverModified: this.serverModified,
908
+ account: this.account,
909
+ accessGroup: this.accessGroup,
910
+ reference: this.reference,
911
+ jobDate: this.jobDate,
912
+ jobStatus: this.jobStatus,
913
+ jobType: this.jobType,
914
+ assignee: this.assignee,
915
+ formId: this.formId,
916
+ timeZoneOffset: this.timeZoneOffset,
917
+ };
725
918
  }
726
- this.dynamicProperties
727
- .forEach(prop => dto[prop] = this.$this[prop]);
919
+ const dto = {};
920
+ [...this.staticProperties, ...this.dynamicProperties]
921
+ .forEach(prop => (dto)[prop] = this.$this[prop]);
728
922
  return dto;
729
923
  }
730
924
  /**
@@ -779,7 +973,33 @@ class VasJobModel extends VasBaseModel {
779
973
  filterArg = (filterArg || '').trim();
780
974
  }
781
975
  const path = key.split('.');
782
- let result = (this.getValueByPath(path) || '').toString();
976
+ const objectKey = path.shift() || '';
977
+ let result = '';
978
+ if (objectKey === 'job') {
979
+ result = (this.getValueByPath(path) || '').toString();
980
+ }
981
+ else if (objectKey === 'fields') {
982
+ result = (getValueByPath(path, this.getFields2()) || '').toString();
983
+ }
984
+ else if (objectKey.length) {
985
+ if (options.objects) {
986
+ if (options.objects[objectKey] === undefined) {
987
+ console.debug(`objectKey ${objectKey} is not present in options.object`);
988
+ result = '';
989
+ }
990
+ else {
991
+ result = (getValueByPath(path, options.objects[objectKey]) || '')
992
+ .toString();
993
+ }
994
+ }
995
+ else {
996
+ console.debug(`objectKey ${objectKey} was used but options.object is not set`);
997
+ return '';
998
+ }
999
+ }
1000
+ else {
1001
+ return '';
1002
+ }
783
1003
  if (filterName && result) {
784
1004
  switch (filterName) {
785
1005
  case 'date': {
@@ -793,7 +1013,7 @@ class VasJobModel extends VasBaseModel {
793
1013
  }
794
1014
  }
795
1015
  return result;
796
- });
1016
+ }).trim();
797
1017
  }
798
1018
  ;
799
1019
  }
@@ -881,5 +1101,5 @@ class VasUserModel extends VasBaseModel {
881
1101
  * Generated bundle index. Do not edit.
882
1102
  */
883
1103
 
884
- export { VasBaseModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFormModel, VasGroupModel, VasJobModel, VasReportRequestModel, VasUserModel };
1104
+ export { VasAccountObjectModel, VasBaseModel, VasBranchModel, VasContactModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFormModel, VasGroupModel, VasJobModel, VasReportRequestModel, VasRestrictedAccountObjectModel, VasUserModel };
885
1105
  //# sourceMappingURL=ironcode-vas-lib.mjs.map