@ironcode/vas-lib 1.0.2 → 1.2.0

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 (81) hide show
  1. package/cjs/lib/entity/vas-base.model.d.ts +8 -0
  2. package/cjs/lib/entity/vas-base.model.d.ts.map +1 -1
  3. package/cjs/lib/entity/vas-base.model.js +9 -0
  4. package/cjs/lib/entity/vas-base.model.js.map +1 -1
  5. package/cjs/lib/entity/vas-branch.model.d.ts.map +1 -1
  6. package/cjs/lib/entity/vas-branch.model.js.map +1 -1
  7. package/cjs/lib/entity/vas-contact.model.d.ts.map +1 -1
  8. package/cjs/lib/entity/vas-contact.model.js.map +1 -1
  9. package/cjs/lib/entity/vas-control-type.model.d.ts.map +1 -1
  10. package/cjs/lib/entity/vas-control-type.model.js +1 -2
  11. package/cjs/lib/entity/vas-control-type.model.js.map +1 -1
  12. package/cjs/lib/entity/vas-control.model.d.ts.map +1 -1
  13. package/cjs/lib/entity/vas-control.model.js +1 -1
  14. package/cjs/lib/entity/vas-control.model.js.map +1 -1
  15. package/cjs/lib/entity/vas-field.model.d.ts.map +1 -1
  16. package/cjs/lib/entity/vas-field.model.js +1 -2
  17. package/cjs/lib/entity/vas-field.model.js.map +1 -1
  18. package/cjs/lib/entity/vas-file.model.d.ts.map +1 -1
  19. package/cjs/lib/entity/vas-file.model.js +1 -2
  20. package/cjs/lib/entity/vas-file.model.js.map +1 -1
  21. package/cjs/lib/entity/vas-form.model.d.ts.map +1 -1
  22. package/cjs/lib/entity/vas-form.model.js.map +1 -1
  23. package/cjs/lib/entity/vas-group.model.d.ts.map +1 -1
  24. package/cjs/lib/entity/vas-group.model.js +1 -2
  25. package/cjs/lib/entity/vas-group.model.js.map +1 -1
  26. package/cjs/lib/entity/vas-instruction-job-field.model.d.ts.map +1 -1
  27. package/cjs/lib/entity/vas-instruction-job-field.model.js.map +1 -1
  28. package/cjs/lib/entity/vas-instruction-job.model.d.ts.map +1 -1
  29. package/cjs/lib/entity/vas-instruction-job.model.js.map +1 -1
  30. package/cjs/lib/entity/vas-instruction-provider.model.d.ts.map +1 -1
  31. package/cjs/lib/entity/vas-instruction-provider.model.js.map +1 -1
  32. package/cjs/lib/entity/vas-instruction.model.d.ts.map +1 -1
  33. package/cjs/lib/entity/vas-instruction.model.js.map +1 -1
  34. package/cjs/lib/entity/vas-invitation.d.ts.map +1 -1
  35. package/cjs/lib/entity/vas-invitation.js.map +1 -1
  36. package/cjs/lib/entity/vas-job.model.d.ts +55 -66
  37. package/cjs/lib/entity/vas-job.model.d.ts.map +1 -1
  38. package/cjs/lib/entity/vas-job.model.js +91 -68
  39. package/cjs/lib/entity/vas-job.model.js.map +1 -1
  40. package/cjs/lib/entity/vas-membership.model.d.ts.map +1 -1
  41. package/cjs/lib/entity/vas-membership.model.js +1 -1
  42. package/cjs/lib/entity/vas-membership.model.js.map +1 -1
  43. package/cjs/lib/entity/vas-note.model.d.ts +1 -0
  44. package/cjs/lib/entity/vas-note.model.d.ts.map +1 -1
  45. package/cjs/lib/entity/vas-note.model.js +3 -0
  46. package/cjs/lib/entity/vas-note.model.js.map +1 -1
  47. package/cjs/lib/entity/vas-report-request.model.d.ts.map +1 -1
  48. package/cjs/lib/entity/vas-report-request.model.js +1 -4
  49. package/cjs/lib/entity/vas-report-request.model.js.map +1 -1
  50. package/cjs/lib/entity/vas-report.model.d.ts.map +1 -1
  51. package/cjs/lib/entity/vas-report.model.js.map +1 -1
  52. package/cjs/lib/entity/vas-user.model.d.ts.map +1 -1
  53. package/cjs/lib/entity/vas-user.model.js.map +1 -1
  54. package/esm2020/lib/entity/vas-base.model.mjs +18 -1
  55. package/esm2020/lib/entity/vas-branch.model.mjs +1 -1
  56. package/esm2020/lib/entity/vas-contact.model.mjs +1 -1
  57. package/esm2020/lib/entity/vas-control-type.model.mjs +2 -3
  58. package/esm2020/lib/entity/vas-control.model.mjs +2 -2
  59. package/esm2020/lib/entity/vas-field.model.mjs +2 -3
  60. package/esm2020/lib/entity/vas-file.model.mjs +2 -3
  61. package/esm2020/lib/entity/vas-form.model.mjs +1 -1
  62. package/esm2020/lib/entity/vas-group.model.mjs +2 -3
  63. package/esm2020/lib/entity/vas-instruction-job-field.model.mjs +1 -1
  64. package/esm2020/lib/entity/vas-instruction-job.model.mjs +1 -1
  65. package/esm2020/lib/entity/vas-instruction-provider.model.mjs +1 -1
  66. package/esm2020/lib/entity/vas-instruction.model.mjs +1 -1
  67. package/esm2020/lib/entity/vas-invitation.mjs +1 -1
  68. package/esm2020/lib/entity/vas-job.model.mjs +91 -69
  69. package/esm2020/lib/entity/vas-membership.model.mjs +2 -2
  70. package/esm2020/lib/entity/vas-note.model.mjs +10 -1
  71. package/esm2020/lib/entity/vas-report-request.model.mjs +2 -4
  72. package/esm2020/lib/entity/vas-report.model.mjs +1 -1
  73. package/esm2020/lib/entity/vas-user.model.mjs +1 -1
  74. package/fesm2015/ironcode-vas-lib.mjs +107 -75
  75. package/fesm2015/ironcode-vas-lib.mjs.map +1 -1
  76. package/fesm2020/ironcode-vas-lib.mjs +121 -75
  77. package/fesm2020/ironcode-vas-lib.mjs.map +1 -1
  78. package/lib/entity/vas-base.model.d.ts +8 -0
  79. package/lib/entity/vas-job.model.d.ts +55 -66
  80. package/lib/entity/vas-note.model.d.ts +1 -0
  81. package/package.json +1 -1
@@ -1,4 +1,9 @@
1
1
  import { VasBaseDto } from './vas-base.dto';
2
+ import { VasUserDto } from './vas-user.dto';
3
+ interface VasModelStatic<T extends VasBaseModel> {
4
+ new (...args: any[]): T;
5
+ fromDto(dto: Partial<VasBaseDto>): T;
6
+ }
2
7
  /**
3
8
  * BaseEntityModel
4
9
  */
@@ -13,4 +18,7 @@ export declare class VasBaseModel implements VasBaseDto {
13
18
  createdByName: string;
14
19
  modifiedByName: string;
15
20
  constructor(id: string, created: string, serverCreated: string, createdBy: string, modified: string, serverModified: string, modifiedBy: string, createdByName: string, modifiedByName: string);
21
+ static fromDto(dto: Partial<VasBaseDto>): VasBaseModel;
22
+ static create<T extends VasBaseDto>(this: VasModelStatic<T>, user: VasUserDto, values?: Partial<T>): T;
16
23
  }
24
+ export {};
@@ -5,6 +5,7 @@ import { VasFormModel } from './vas-form.model';
5
5
  import { VasJobDto } from './vas-job.dto';
6
6
  import { VasRestrictedAccountObjectModel } from './vas-restricted-account-object.model';
7
7
  import { GeoLocation } from '../model/geo-location';
8
+ import { VasFormDto } from './vas-form.dto';
8
9
  export declare interface VasJobModelDynamicInterface {
9
10
  [s: string]: string | number | Record<string, VasFieldDtoValue>;
10
11
  }
@@ -54,8 +55,7 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
54
55
  */
55
56
  get dynamicProperties(): Array<string>;
56
57
  /**
57
- * Returns a list of Job static properties i.e. those that are declared by
58
- * the type
58
+ * Returns the list of properties of the Job type
59
59
  */
60
60
  get staticProperties(): Array<string>;
61
61
  /**
@@ -63,6 +63,13 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
63
63
  */
64
64
  static empty(): VasJobModel;
65
65
  static fromDto(dto: Partial<VasJobDto>): VasJobModel;
66
+ /**
67
+ * This method will instantiate a new JobModel. The difference with this
68
+ * method of instantiation is that we are coming from a relation frame i.e.
69
+ * the job has a list of {@link VasFieldDto} instead of a Job document.
70
+ *
71
+ */
72
+ static fromRelational(dto: Partial<VasJobDto>, form: VasFormDto): VasJobModel;
66
73
  /**
67
74
  * @param {VasFormModel} formModel
68
75
  * @return {Record<string, VasFieldDtoValue>}
@@ -75,7 +82,7 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
75
82
  * return a property regardless (because it uses the form to drive the logic)
76
83
  * @return {Record<string, VasFieldDtoValue>}
77
84
  */
78
- getFields2(): Record<string, VasFieldDtoValue>;
85
+ protected getFields2(): Record<string, VasFieldDtoValue>;
79
86
  /**
80
87
  * Returns an object describing how many attachments were added to this job
81
88
  * (camera controls and files), and how many have not been uploaded yet.
@@ -88,18 +95,41 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
88
95
  total: number;
89
96
  };
90
97
  /**
91
- * This method will hydrate the `fields` property of the model. The reason for
92
- * this is that we have different ways to store the field data. One way, is
93
- * we store them as dynamic properties of the job. For example job.foo.bar,
94
- * where `foo` is the name of a Group, and `bar` is the name of a control.
95
- * Thus, when we create a job using a form in the client, the job object will
96
- * have its static properties (id, account, reference etc), and also a number
97
- * of dynamic properties determined by the Groups and Controls. This kind of
98
- * object is nice to work with in certain circumstances. However, the api
99
- * works differently. In the API a Job is a record, and references a number of
100
- * Field records. Each Field stores the value. Comparing these two models we
101
- * have:
102
- * A) job with dynamic properties, e.g.
98
+ * This method will return the dynamic property from the JobModel that
99
+ * represent a group (from a form).
100
+ *
101
+ * @param name the name of the group
102
+ * @param init if true (default) and group is not found, initialise an empty
103
+ * group, otherwise throw an error
104
+ */
105
+ getGroup(name: string, init?: boolean): Record<string, VasFieldDtoValue>;
106
+ /**
107
+ * @param path path segments
108
+ */
109
+ getValueByPath<T extends VasFieldDtoValue>(path?: string[]): T | undefined;
110
+ /**
111
+ * In order to understand why we need this method it is important to
112
+ * understand that within the system, Jobs can be represented in one of two
113
+ * ways, document and relational.
114
+ *
115
+ * The important distinction is how values submitted by a form are stored.
116
+ *
117
+ * Jobs stored as documents (JSON objects) will store user values, as dynamic
118
+ * properties of the document.
119
+ *
120
+ * Whereas, Jobs stored as relational, will store user values in an array of
121
+ * {@link VasFieldDto} objects.
122
+ *
123
+ * Depending on where we are in the system, either one of these approaches can
124
+ * be more useful than the other.
125
+ *
126
+ * This method, assumes that the JobModel has been instantiated from a
127
+ * document representation, and serves to hydrate the fields array. In order
128
+ * to achieve this, knowledge of the {@link VasFormDto} that created the job
129
+ * is required.
130
+ *
131
+ *
132
+ * Job in document representation
103
133
  * {
104
134
  * id: <guid>,
105
135
  * reference: "something"
@@ -109,7 +139,7 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
109
139
  * }
110
140
  * }
111
141
  *
112
- * B) job with fields
142
+ * Job in relational representation
113
143
  * {
114
144
  * id: <guid>,
115
145
  * reference: "something"
@@ -124,55 +154,15 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
124
154
  * ]
125
155
  * }
126
156
  *
127
- * So, what this method does is given a JobModel in the form of A, read all
128
- * of those dynamic properties and set them into `fields`. Doing this requires
129
- * knowledge of the Form that was used to create the job. Moreover, since the
130
- * dynamic properties do not contain the ids of the fields, we also allow to
131
- * pass in a `controlFieldIdMap`. This map stores the mapping between Control
132
- * and the Field that was created in the Job to store the value for that
133
- * Control. This is useful, if for example you want to compare a Job in form A
134
- * with a Job in form B, for example if you want to update the Job on the API
135
- * with a Job that was saved by a client in form A.
136
- *
137
- * E.g.
138
- * Client -> API: client requests form
139
- * User -> Client: user fills in the form and submits
140
- * Client -> Firestore: client saves the Job in form A i.e. dynamic props
141
- * Firestore -> Function: A function is triggered to sync the job to the API
142
- * Function -> API: Function checks if job already exists, it receives 404
143
- * Function -> Function: The function calls `hydrateFields(...)`
144
- * Function -> API: The function POST the Job to /jobs
145
- * Function -> API: The function POST each field to /fields
146
- *
147
- * Similarly, if the user updates the job
148
- * Client -> API: client requests form
149
- * User -> Client: user fills in the form and submits an update
150
- * Client -> Firestore: client saves the Job in form A i.e. dynamic props
151
- * Firestore -> Function: A function is triggered to sync the job to the API
152
- * Function -> API: Function checks if job already exists, it receives 200
153
- * Function -> Function: The function calls `hydrateFields(...)` passing in
154
- * the map is made by iterating over the fields it
155
- * received from the API and storing the mappings
156
- * between controlId and fieldId for each field
157
- * Function -> API: The function PATCH the Job to /jobs
158
- * Function -> API: The function POST/PATCH each field to /fields
159
- * treated as new
160
- *
161
- * @param {VasFormModel} formModel the VasFormModel that was used to create
162
- * the job
163
- * @param {Map<string, string>} controlFieldIdMap a mapping of control to
164
- * field ids. This is used to determine whether a new id for the field should
165
- * be generated, or to reuse an existing one from the map.
166
- * @param {Array<string>} controlNames if a value is provided, it will be used
157
+ *
158
+ * @param formModel the VasFormModel that was used to create the job
159
+ * @param controlFieldIdMap This is used to determine the id each field.
160
+ * Either one will be found in the map, or a new one is generated.
161
+ * @param controlNames if a value is provided, it will be used
167
162
  * to filter the fields that are returned.
168
163
  * @return {Array<VasFieldDto>}
169
164
  */
170
165
  hydrateFields(formModel: VasFormModel, controlFieldIdMap?: Map<string, string>, controlNames?: Array<string>): void;
171
- /**
172
- * @param {string[]} path path segments
173
- * @return {void}
174
- */
175
- getValueByPath<T extends VasFieldDtoValue>(path?: string[]): T | undefined;
176
166
  /**
177
167
  * A very non sophisticated way to set values in the job via paths
178
168
  *
@@ -187,14 +177,13 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
187
177
  * }
188
178
  * }
189
179
  *
190
- * @param {any} value the value to set
191
- * @param {string[]} path path segments
180
+ * @param value the value to set
181
+ * @param path path segments
192
182
  */
193
183
  setValueByPath(value: VasFieldDtoValue, path?: string[]): void;
194
184
  /**
195
- * @param {boolean} staticOnly if true, will only output values for the static
185
+ * @param staticOnly if true, will only output values for the static
196
186
  * properties in the dto
197
- * @return {VasJobDto}
198
187
  */
199
188
  toDto(staticOnly?: boolean): VasJobDto;
200
189
  /**
@@ -221,7 +210,7 @@ export declare class VasJobModel extends VasRestrictedAccountObjectModel {
221
210
  *
222
211
  * @param {string} value a string with the syntax
223
212
  * @param {ParseSyntaxOptions} options
224
- * @return {string} the results of parsing the syntax on this job
213
+ * @return the results of parsing the syntax on this job
225
214
  */
226
215
  parseSyntax(value: string, options?: ParseSyntaxOptions): string;
227
216
  /**
@@ -27,4 +27,5 @@ export declare class VasNoteModel extends VasJobDataModel implements VasNoteDto
27
27
  * @returns VasNoteDto
28
28
  */
29
29
  toDto(): VasNoteDto;
30
+ toApiDto(options?: any): Record<string, string | number | boolean>;
30
31
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ironcode/vas-lib",
3
- "version": "1.0.2",
3
+ "version": "1.2.0",
4
4
  "peerDependencies": {
5
5
  "angular2-uuid": "^1.1.1",
6
6
  "moment": "^2.0.0"