@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
@@ -512,10 +649,75 @@ class VasFormModel extends VasBaseModel {
512
649
  title: this.title,
513
650
  description: this.description,
514
651
  groups: this.groups.map(group => group.toDto()),
652
+ dynamicDescriptor: this.dynamicDescriptor
515
653
  };
516
654
  }
517
655
  }
518
656
 
657
+ /**
658
+ * A non sophisticated way to get values from the job via paths. For example:
659
+ *
660
+ * getValueByPath(
661
+ * ['foo', 'bar'],
662
+ * {
663
+ * foo: {
664
+ * bar: 'value'
665
+ * }
666
+ * }
667
+ * );
668
+ *
669
+ * will return "value"
670
+ * @param {string[]} path
671
+ * @param {Record<string, VasFieldDtoValue>} object
672
+ * @return {T | undefined}
673
+ */
674
+ const getValueByPath = (path, object) => {
675
+ switch (path.length) {
676
+ case 0: {
677
+ return;
678
+ }
679
+ case 1: {
680
+ return (object)[path[0]];
681
+ }
682
+ case 2: {
683
+ const val0 = object[path[0]];
684
+ if (!val0) {
685
+ return undefined;
686
+ }
687
+ return val0[path[1]];
688
+ }
689
+ case 3: {
690
+ const val0 = object[path[0]];
691
+ if (!val0) {
692
+ return undefined;
693
+ }
694
+ const val1 = val0[path[1]];
695
+ if (!val1) {
696
+ return undefined;
697
+ }
698
+ return val1[path[2]];
699
+ }
700
+ case 4: {
701
+ const val0 = object[path[0]];
702
+ if (!val0) {
703
+ return undefined;
704
+ }
705
+ const val1 = val0[path[1]];
706
+ if (!val1) {
707
+ return undefined;
708
+ }
709
+ const val2 = val1[path[2]];
710
+ if (!val2) {
711
+ return undefined;
712
+ }
713
+ return val2[path[3]];
714
+ }
715
+ default: {
716
+ throw Error('path has too many segments');
717
+ }
718
+ }
719
+ };
720
+
519
721
  /**
520
722
  * JobModel
521
723
  */
@@ -562,8 +764,6 @@ class VasJobModel extends VasBaseModel {
562
764
  * @return {VasJobModelDynamicInterface}
563
765
  */
564
766
  get $this() {
565
- // eslint-disable-next-line @typescript-eslint/no-this-alias
566
- const $this = this;
567
767
  return this;
568
768
  }
569
769
  /**
@@ -622,54 +822,33 @@ class VasJobModel extends VasBaseModel {
622
822
  return fields;
623
823
  }
624
824
  /**
625
- * A very non sophisticated way to get values from the job via paths
626
- *
627
- * For example:
628
- *
629
- * getValueByPath(['foo', 'bar']);
630
- *
631
- * if job is
632
- * {
633
- * foo: {
634
- * bar: 'value'
635
- * }
636
- * }
637
- *
638
- * will return "value"
639
- *
825
+ * Will return an object whose keys are the names of all fields in the job but
826
+ * with the "fields." part removed. This method is similar to `getFields`
827
+ * except that this method will only return values that are set whereas
828
+ * `getFields` will return a property regardless (because it uses the form to
829
+ * drive the logic)
830
+ * @return {Record<string, VasFieldDtoValue>}
831
+ */
832
+ getFields2() {
833
+ let fields = {};
834
+ this.dynamicProperties
835
+ .forEach((groupName) => {
836
+ Object
837
+ .keys(this.$this[groupName])
838
+ .forEach(controlName => {
839
+ const controlNameShort = controlName.replace(/fields\./, '');
840
+ fields[controlNameShort] = this.getValueByPath([groupName, controlName]);
841
+ });
842
+ }, {});
843
+ return fields;
844
+ }
845
+ /**
846
+
640
847
  * @param {string[]} path path segments
641
848
  * @return {void}
642
849
  */
643
850
  getValueByPath(path = []) {
644
- switch (path.length) {
645
- case 0: {
646
- return;
647
- }
648
- case 1: {
649
- return (this.$this)[path[0]];
650
- }
651
- case 2: {
652
- const val0 = this.$this[path[0]];
653
- if (!val0) {
654
- return undefined;
655
- }
656
- return val0[path[1]];
657
- }
658
- case 3: {
659
- const val0 = this.$this[path[0]];
660
- if (!val0) {
661
- return undefined;
662
- }
663
- const val1 = val0[path[1]];
664
- if (!val1) {
665
- return undefined;
666
- }
667
- return val1[path[2]];
668
- }
669
- default: {
670
- throw Error('path has too many segments');
671
- }
672
- }
851
+ return getValueByPath(path, this.$this);
673
852
  }
674
853
  /**
675
854
  * A very non sophisticated way to set values in the job via paths
@@ -694,7 +873,7 @@ class VasJobModel extends VasBaseModel {
694
873
  return;
695
874
  }
696
875
  case 1: {
697
- (this.$this)[path[0]] = value;
876
+ this[path[0]] = value;
698
877
  return;
699
878
  }
700
879
  case 2: {
@@ -718,14 +897,29 @@ class VasJobModel extends VasBaseModel {
718
897
  * @return {VasJobDto}
719
898
  */
720
899
  toDto(staticOnly = false) {
721
- const dto = {};
722
- this.staticProperties
723
- .forEach(prop => (dto)[prop] = this.$this[prop]);
724
900
  if (staticOnly) {
725
- return dto;
901
+ return {
902
+ id: this.id,
903
+ created: this.created,
904
+ createdBy: this.createdBy,
905
+ modified: this.modified,
906
+ modifiedBy: this.modifiedBy,
907
+ serverCreated: this.serverCreated,
908
+ serverModified: this.serverModified,
909
+ account: this.account,
910
+ accessGroup: this.accessGroup,
911
+ reference: this.reference,
912
+ jobDate: this.jobDate,
913
+ jobStatus: this.jobStatus,
914
+ jobType: this.jobType,
915
+ assignee: this.assignee,
916
+ formId: this.formId,
917
+ timeZoneOffset: this.timeZoneOffset,
918
+ };
726
919
  }
727
- this.dynamicProperties
728
- .forEach(prop => dto[prop] = this.$this[prop]);
920
+ const dto = {};
921
+ [...this.staticProperties, ...this.dynamicProperties]
922
+ .forEach(prop => (dto)[prop] = this.$this[prop]);
729
923
  return dto;
730
924
  }
731
925
  /**
@@ -780,7 +974,33 @@ class VasJobModel extends VasBaseModel {
780
974
  filterArg = (filterArg || '').trim();
781
975
  }
782
976
  const path = key.split('.');
783
- let result = (this.getValueByPath(path) || '').toString();
977
+ const objectKey = path.shift() || '';
978
+ let result = '';
979
+ if (objectKey === 'job') {
980
+ result = (this.getValueByPath(path) || '').toString();
981
+ }
982
+ else if (objectKey === 'fields') {
983
+ result = (getValueByPath(path, this.getFields2()) || '').toString();
984
+ }
985
+ else if (objectKey.length) {
986
+ if (options.objects) {
987
+ if (options.objects[objectKey] === undefined) {
988
+ console.debug(`objectKey ${objectKey} is not present in options.object`);
989
+ result = '';
990
+ }
991
+ else {
992
+ result = (getValueByPath(path, options.objects[objectKey]) || '')
993
+ .toString();
994
+ }
995
+ }
996
+ else {
997
+ console.debug(`objectKey ${objectKey} was used but options.object is not set`);
998
+ return '';
999
+ }
1000
+ }
1001
+ else {
1002
+ return '';
1003
+ }
784
1004
  if (filterName && result) {
785
1005
  switch (filterName) {
786
1006
  case 'date': {
@@ -794,7 +1014,7 @@ class VasJobModel extends VasBaseModel {
794
1014
  }
795
1015
  }
796
1016
  return result;
797
- });
1017
+ }).trim();
798
1018
  }
799
1019
  ;
800
1020
  }
@@ -882,5 +1102,5 @@ class VasUserModel extends VasBaseModel {
882
1102
  * Generated bundle index. Do not edit.
883
1103
  */
884
1104
 
885
- export { VasBaseModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFormModel, VasGroupModel, VasJobModel, VasReportRequestModel, VasUserModel };
1105
+ export { VasAccountObjectModel, VasBaseModel, VasBranchModel, VasContactModel, VasControlConfigDirection, VasControlModel, VasControlTypeModel, VasFormModel, VasGroupModel, VasJobModel, VasReportRequestModel, VasRestrictedAccountObjectModel, VasUserModel };
886
1106
  //# sourceMappingURL=ironcode-vas-lib.mjs.map