@ironcode/vas-lib 1.1.0 → 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.
- package/cjs/lib/entity/vas-job.model.d.ts +55 -66
- package/cjs/lib/entity/vas-job.model.d.ts.map +1 -1
- package/cjs/lib/entity/vas-job.model.js +91 -68
- package/cjs/lib/entity/vas-job.model.js.map +1 -1
- package/esm2020/lib/entity/vas-job.model.mjs +91 -69
- package/fesm2015/ironcode-vas-lib.mjs +91 -68
- package/fesm2015/ironcode-vas-lib.mjs.map +1 -1
- package/fesm2020/ironcode-vas-lib.mjs +90 -68
- package/fesm2020/ironcode-vas-lib.mjs.map +1 -1
- package/lib/entity/vas-job.model.d.ts +55 -66
- package/package.json +1 -1
|
@@ -1619,8 +1619,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1619
1619
|
.filter(prop => !nativeProps.includes(prop));
|
|
1620
1620
|
}
|
|
1621
1621
|
/**
|
|
1622
|
-
* Returns
|
|
1623
|
-
* the type
|
|
1622
|
+
* Returns the list of properties of the Job type
|
|
1624
1623
|
*/
|
|
1625
1624
|
get staticProperties() {
|
|
1626
1625
|
return Object.getOwnPropertyNames(VasJobModel.empty());
|
|
@@ -1640,6 +1639,28 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1640
1639
|
.forEach((key) => model.$this[key] = dto[key]);
|
|
1641
1640
|
return model;
|
|
1642
1641
|
}
|
|
1642
|
+
/**
|
|
1643
|
+
* This method will instantiate a new JobModel. The difference with this
|
|
1644
|
+
* method of instantiation is that we are coming from a relation frame i.e.
|
|
1645
|
+
* the job has a list of {@link VasFieldDto} instead of a Job document.
|
|
1646
|
+
*
|
|
1647
|
+
*/
|
|
1648
|
+
static fromRelational(dto, form) {
|
|
1649
|
+
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$1().utcOffset(), dto.pendingFields || 0, dto.childModified || '', dto.version || 0, dto.fields || [], dto.files || [], dto.createdByDisplayName || '', dto.modifiedByDisplayName || '', dto.geoLocation || getEmptyGeoLocation());
|
|
1650
|
+
form.groups
|
|
1651
|
+
.forEach(group => {
|
|
1652
|
+
group.controls
|
|
1653
|
+
.forEach(control => {
|
|
1654
|
+
var _a;
|
|
1655
|
+
const field = (_a = dto.fields) === null || _a === void 0 ? void 0 : _a.find(f => f.control === control.id);
|
|
1656
|
+
if (!field) {
|
|
1657
|
+
return;
|
|
1658
|
+
}
|
|
1659
|
+
model.getGroup(group.name)[control.name] = field.value;
|
|
1660
|
+
});
|
|
1661
|
+
});
|
|
1662
|
+
return model;
|
|
1663
|
+
}
|
|
1643
1664
|
/**
|
|
1644
1665
|
* @param {VasFormModel} formModel
|
|
1645
1666
|
* @return {Record<string, VasFieldDtoValue>}
|
|
@@ -1720,18 +1741,63 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1720
1741
|
};
|
|
1721
1742
|
}
|
|
1722
1743
|
/**
|
|
1723
|
-
* This method will
|
|
1724
|
-
*
|
|
1725
|
-
*
|
|
1726
|
-
*
|
|
1727
|
-
*
|
|
1728
|
-
*
|
|
1729
|
-
|
|
1730
|
-
|
|
1731
|
-
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1744
|
+
* This method will return the dynamic property from the JobModel that
|
|
1745
|
+
* represent a group (from a form).
|
|
1746
|
+
*
|
|
1747
|
+
* @param name the name of the group
|
|
1748
|
+
* @param init if true (default) and group is not found, initialise an empty
|
|
1749
|
+
* group, otherwise throw an error
|
|
1750
|
+
*/
|
|
1751
|
+
getGroup(name, init = true) {
|
|
1752
|
+
let prop;
|
|
1753
|
+
if (this.staticProperties.includes(name)) {
|
|
1754
|
+
throw Error(`invalid group name ${name}, not a dynamic property`);
|
|
1755
|
+
}
|
|
1756
|
+
else if (this.$this[name] === undefined) {
|
|
1757
|
+
if (init) {
|
|
1758
|
+
prop = this.$this[name] = {};
|
|
1759
|
+
}
|
|
1760
|
+
else {
|
|
1761
|
+
throw Error(`invalid group name ${name}, not found`);
|
|
1762
|
+
}
|
|
1763
|
+
}
|
|
1764
|
+
else {
|
|
1765
|
+
prop = this.$this[name];
|
|
1766
|
+
if (typeof prop !== 'object') {
|
|
1767
|
+
throw Error(`invalid group name ${name}, not an object`);
|
|
1768
|
+
}
|
|
1769
|
+
}
|
|
1770
|
+
return prop;
|
|
1771
|
+
}
|
|
1772
|
+
/**
|
|
1773
|
+
* @param path path segments
|
|
1774
|
+
*/
|
|
1775
|
+
getValueByPath(path = []) {
|
|
1776
|
+
return getValueByPath(path, this.$this);
|
|
1777
|
+
}
|
|
1778
|
+
/**
|
|
1779
|
+
* In order to understand why we need this method it is important to
|
|
1780
|
+
* understand that within the system, Jobs can be represented in one of two
|
|
1781
|
+
* ways, document and relational.
|
|
1782
|
+
*
|
|
1783
|
+
* The important distinction is how values submitted by a form are stored.
|
|
1784
|
+
*
|
|
1785
|
+
* Jobs stored as documents (JSON objects) will store user values, as dynamic
|
|
1786
|
+
* properties of the document.
|
|
1787
|
+
*
|
|
1788
|
+
* Whereas, Jobs stored as relational, will store user values in an array of
|
|
1789
|
+
* {@link VasFieldDto} objects.
|
|
1790
|
+
*
|
|
1791
|
+
* Depending on where we are in the system, either one of these approaches can
|
|
1792
|
+
* be more useful than the other.
|
|
1793
|
+
*
|
|
1794
|
+
* This method, assumes that the JobModel has been instantiated from a
|
|
1795
|
+
* document representation, and serves to hydrate the fields array. In order
|
|
1796
|
+
* to achieve this, knowledge of the {@link VasFormDto} that created the job
|
|
1797
|
+
* is required.
|
|
1798
|
+
*
|
|
1799
|
+
*
|
|
1800
|
+
* Job in document representation
|
|
1735
1801
|
* {
|
|
1736
1802
|
* id: <guid>,
|
|
1737
1803
|
* reference: "something"
|
|
@@ -1741,7 +1807,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1741
1807
|
* }
|
|
1742
1808
|
* }
|
|
1743
1809
|
*
|
|
1744
|
-
*
|
|
1810
|
+
* Job in relational representation
|
|
1745
1811
|
* {
|
|
1746
1812
|
* id: <guid>,
|
|
1747
1813
|
* reference: "something"
|
|
@@ -1756,46 +1822,11 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1756
1822
|
* ]
|
|
1757
1823
|
* }
|
|
1758
1824
|
*
|
|
1759
|
-
* So, what this method does is given a JobModel in the form of A, read all
|
|
1760
|
-
* of those dynamic properties and set them into `fields`. Doing this requires
|
|
1761
|
-
* knowledge of the Form that was used to create the job. Moreover, since the
|
|
1762
|
-
* dynamic properties do not contain the ids of the fields, we also allow to
|
|
1763
|
-
* pass in a `controlFieldIdMap`. This map stores the mapping between Control
|
|
1764
|
-
* and the Field that was created in the Job to store the value for that
|
|
1765
|
-
* Control. This is useful, if for example you want to compare a Job in form A
|
|
1766
|
-
* with a Job in form B, for example if you want to update the Job on the API
|
|
1767
|
-
* with a Job that was saved by a client in form A.
|
|
1768
|
-
*
|
|
1769
|
-
* E.g.
|
|
1770
|
-
* Client -> API: client requests form
|
|
1771
|
-
* User -> Client: user fills in the form and submits
|
|
1772
|
-
* Client -> Firestore: client saves the Job in form A i.e. dynamic props
|
|
1773
|
-
* Firestore -> Function: A function is triggered to sync the job to the API
|
|
1774
|
-
* Function -> API: Function checks if job already exists, it receives 404
|
|
1775
|
-
* Function -> Function: The function calls `hydrateFields(...)`
|
|
1776
|
-
* Function -> API: The function POST the Job to /jobs
|
|
1777
|
-
* Function -> API: The function POST each field to /fields
|
|
1778
|
-
*
|
|
1779
|
-
* Similarly, if the user updates the job
|
|
1780
|
-
* Client -> API: client requests form
|
|
1781
|
-
* User -> Client: user fills in the form and submits an update
|
|
1782
|
-
* Client -> Firestore: client saves the Job in form A i.e. dynamic props
|
|
1783
|
-
* Firestore -> Function: A function is triggered to sync the job to the API
|
|
1784
|
-
* Function -> API: Function checks if job already exists, it receives 200
|
|
1785
|
-
* Function -> Function: The function calls `hydrateFields(...)` passing in
|
|
1786
|
-
* the map is made by iterating over the fields it
|
|
1787
|
-
* received from the API and storing the mappings
|
|
1788
|
-
* between controlId and fieldId for each field
|
|
1789
|
-
* Function -> API: The function PATCH the Job to /jobs
|
|
1790
|
-
* Function -> API: The function POST/PATCH each field to /fields
|
|
1791
|
-
* treated as new
|
|
1792
1825
|
*
|
|
1793
|
-
* @param
|
|
1794
|
-
* the
|
|
1795
|
-
*
|
|
1796
|
-
*
|
|
1797
|
-
* be generated, or to reuse an existing one from the map.
|
|
1798
|
-
* @param {Array<string>} controlNames if a value is provided, it will be used
|
|
1826
|
+
* @param formModel the VasFormModel that was used to create the job
|
|
1827
|
+
* @param controlFieldIdMap This is used to determine the id each field.
|
|
1828
|
+
* Either one will be found in the map, or a new one is generated.
|
|
1829
|
+
* @param controlNames if a value is provided, it will be used
|
|
1799
1830
|
* to filter the fields that are returned.
|
|
1800
1831
|
* @return {Array<VasFieldDto>}
|
|
1801
1832
|
*/
|
|
@@ -1827,13 +1858,6 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1827
1858
|
});
|
|
1828
1859
|
this.fields = fields;
|
|
1829
1860
|
}
|
|
1830
|
-
/**
|
|
1831
|
-
* @param {string[]} path path segments
|
|
1832
|
-
* @return {void}
|
|
1833
|
-
*/
|
|
1834
|
-
getValueByPath(path = []) {
|
|
1835
|
-
return getValueByPath(path, this.$this);
|
|
1836
|
-
}
|
|
1837
1861
|
/**
|
|
1838
1862
|
* A very non sophisticated way to set values in the job via paths
|
|
1839
1863
|
*
|
|
@@ -1848,8 +1872,8 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1848
1872
|
* }
|
|
1849
1873
|
* }
|
|
1850
1874
|
*
|
|
1851
|
-
* @param
|
|
1852
|
-
* @param
|
|
1875
|
+
* @param value the value to set
|
|
1876
|
+
* @param path path segments
|
|
1853
1877
|
*/
|
|
1854
1878
|
setValueByPath(value, path = []) {
|
|
1855
1879
|
switch (path.length) {
|
|
@@ -1876,9 +1900,8 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1876
1900
|
}
|
|
1877
1901
|
}
|
|
1878
1902
|
/**
|
|
1879
|
-
* @param
|
|
1903
|
+
* @param staticOnly if true, will only output values for the static
|
|
1880
1904
|
* properties in the dto
|
|
1881
|
-
* @return {VasJobDto}
|
|
1882
1905
|
*/
|
|
1883
1906
|
toDto(staticOnly = false) {
|
|
1884
1907
|
if (staticOnly) {
|
|
@@ -1913,7 +1936,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1913
1936
|
}
|
|
1914
1937
|
const dto = {};
|
|
1915
1938
|
[...this.staticProperties, ...this.dynamicProperties]
|
|
1916
|
-
.forEach(prop =>
|
|
1939
|
+
.forEach(prop => dto[prop] = this.$this[prop]);
|
|
1917
1940
|
return dto;
|
|
1918
1941
|
}
|
|
1919
1942
|
/**
|
|
@@ -1940,7 +1963,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1940
1963
|
*
|
|
1941
1964
|
* @param {string} value a string with the syntax
|
|
1942
1965
|
* @param {ParseSyntaxOptions} options
|
|
1943
|
-
* @return
|
|
1966
|
+
* @return the results of parsing the syntax on this job
|
|
1944
1967
|
*/
|
|
1945
1968
|
parseSyntax(value, options = {
|
|
1946
1969
|
timeZoneOffset: 0
|
|
@@ -1974,7 +1997,7 @@ class VasJobModel extends VasRestrictedAccountObjectModel {
|
|
|
1974
1997
|
result = (this.getValueByPath(path) || '').toString();
|
|
1975
1998
|
}
|
|
1976
1999
|
else if (objectKey === 'fields') {
|
|
1977
|
-
result = (getValueByPath(path, this.getFields2()) || '').toString();
|
|
2000
|
+
result = (getValueByPath(['fields.' + path.shift(), ...path], this.getFields2()) || '').toString();
|
|
1978
2001
|
}
|
|
1979
2002
|
else if (objectKey.length) {
|
|
1980
2003
|
if (options.objects) {
|