@optimiser/common 1.0.380 → 1.0.381

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.
@@ -1855,12 +1855,16 @@ function CheckDataBeforeAdd(updateObj, objectSchema, db) {
1855
1855
  switch (_b.label) {
1856
1856
  case 0:
1857
1857
  _loop_11 = function (fldName) {
1858
- var fieldSchema, sequenceDocument, val, j, item, num;
1858
+ var fieldSchema, cityfield, sequenceDocument, val, j, item, num;
1859
1859
  return __generator(this, function (_c) {
1860
1860
  switch (_c.label) {
1861
1861
  case 0:
1862
1862
  fieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fldName; });
1863
- if (!fieldSchema) return [3 /*break*/, 7];
1863
+ if (!fieldSchema) return [3 /*break*/, 9];
1864
+ cityfield = void 0;
1865
+ if (fieldSchema.LookupObject == "City") {
1866
+ cityfield = updateObj[fldName];
1867
+ }
1864
1868
  if (!constants_1.default.LookupTypeFields.includes(fieldSchema.UIDataType)) return [3 /*break*/, 2];
1865
1869
  return [4 /*yield*/, BuildLookupDataField(fieldSchema, updateObj, db)];
1866
1870
  case 1:
@@ -1897,7 +1901,14 @@ function CheckDataBeforeAdd(updateObj, objectSchema, db) {
1897
1901
  if (fieldSchema.UIDataType == 'formula')
1898
1902
  delete updateObj[fldName];
1899
1903
  _c.label = 7;
1900
- case 7: return [2 /*return*/];
1904
+ case 7:
1905
+ // QPC-9020 for State and Country Field Server Side Validation
1906
+ return [4 /*yield*/, ValidateStateCountryField(fieldSchema, updateObj, fldName, objectSchema, db, cityfield)];
1907
+ case 8:
1908
+ // QPC-9020 for State and Country Field Server Side Validation
1909
+ _c.sent();
1910
+ _c.label = 9;
1911
+ case 9: return [2 /*return*/];
1901
1912
  }
1902
1913
  });
1903
1914
  };
@@ -1927,16 +1938,20 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1927
1938
  switch (_b.label) {
1928
1939
  case 0:
1929
1940
  _loop_12 = function (fldName) {
1930
- var fieldSchema, oldValue, newValue, isSame;
1941
+ var fieldSchema, cityfield, oldValue, newValue, isSame;
1931
1942
  return __generator(this, function (_c) {
1932
1943
  switch (_c.label) {
1933
1944
  case 0:
1934
1945
  if (!(fldName == '_id')) return [3 /*break*/, 1];
1935
1946
  delete updateObj[fldName];
1936
- return [3 /*break*/, 5];
1947
+ return [3 /*break*/, 7];
1937
1948
  case 1:
1938
1949
  fieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fldName; });
1939
- if (!fieldSchema) return [3 /*break*/, 5];
1950
+ if (!fieldSchema) return [3 /*break*/, 7];
1951
+ cityfield = void 0;
1952
+ if (fieldSchema.LookupObject == "City") {
1953
+ cityfield = updateObj[fldName];
1954
+ }
1940
1955
  if (!(fieldSchema.UIDataType == 'autoincrement' || fieldSchema.UIDataType == 'formula')) return [3 /*break*/, 2];
1941
1956
  delete updateObj[fldName];
1942
1957
  return [3 /*break*/, 5];
@@ -1960,7 +1975,14 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1960
1975
  case 4:
1961
1976
  _c.sent();
1962
1977
  _c.label = 5;
1963
- case 5: return [2 /*return*/];
1978
+ case 5:
1979
+ // QPC-9020 for State and Country Field Server Side Validation
1980
+ return [4 /*yield*/, ValidateStateCountryField(fieldSchema, updateObj, fldName, objectSchema, db, cityfield)];
1981
+ case 6:
1982
+ // QPC-9020 for State and Country Field Server Side Validation
1983
+ _c.sent();
1984
+ _c.label = 7;
1985
+ case 7: return [2 /*return*/];
1964
1986
  }
1965
1987
  });
1966
1988
  };
@@ -5660,3 +5682,40 @@ function SyncTotalSlotRemaining(registrationID, db) {
5660
5682
  });
5661
5683
  }
5662
5684
  exports.SyncTotalSlotRemaining = SyncTotalSlotRemaining;
5685
+ function ValidateStateCountryField(fieldSchema, updateObj, fldName, objectSchema, db, cityfield) {
5686
+ return __awaiter(this, void 0, void 0, function () {
5687
+ var cityDocument, stateFieldSchema, countryFieldSchema, stateFieldSchema, countryFieldSchema;
5688
+ return __generator(this, function (_a) {
5689
+ switch (_a.label) {
5690
+ case 0:
5691
+ if (!((fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.LookupObject) === 'City')) return [3 /*break*/, 3];
5692
+ if (!cityfield) return [3 /*break*/, 2];
5693
+ return [4 /*yield*/, db.collection('City').findOne({ _id: updateObj[fldName] })];
5694
+ case 1:
5695
+ cityDocument = _a.sent();
5696
+ if (cityDocument) {
5697
+ stateFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.StateField; });
5698
+ if (fieldSchema.StateField && ['add', 'edit', 'both'].includes(stateFieldSchema.DisableON)) {
5699
+ updateObj[fieldSchema.StateField] = cityDocument.State;
5700
+ }
5701
+ countryFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.CountryField; });
5702
+ if (fieldSchema.CountryField && ['add', 'edit', 'both'].includes(countryFieldSchema.DisableON)) {
5703
+ updateObj[fieldSchema.CountryField] = cityDocument.CountryID;
5704
+ }
5705
+ }
5706
+ return [3 /*break*/, 3];
5707
+ case 2:
5708
+ stateFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.StateField; });
5709
+ if (fieldSchema.StateField && ['add', 'edit', 'both'].includes(stateFieldSchema.DisableON)) {
5710
+ updateObj[fieldSchema.StateField] = null;
5711
+ }
5712
+ countryFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.CountryField; });
5713
+ if (fieldSchema.CountryField && ['add', 'edit', 'both'].includes(countryFieldSchema.DisableON)) {
5714
+ updateObj[fieldSchema.CountryField] = null;
5715
+ }
5716
+ _a.label = 3;
5717
+ case 3: return [2 /*return*/];
5718
+ }
5719
+ });
5720
+ });
5721
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.380",
3
+ "version": "1.0.381",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {