@optimiser/common 1.0.383 → 1.0.384

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.
@@ -1860,7 +1860,7 @@ function CheckDataBeforeAdd(updateObj, objectSchema, db) {
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
1864
  cityfield = void 0;
1865
1865
  if (fieldSchema.LookupObject == "City") {
1866
1866
  cityfield = updateObj[fldName];
@@ -1901,7 +1901,14 @@ function CheckDataBeforeAdd(updateObj, objectSchema, db) {
1901
1901
  if (fieldSchema.UIDataType == 'formula')
1902
1902
  delete updateObj[fldName];
1903
1903
  _c.label = 7;
1904
- 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: fieldSchema, updateObj: updateObj, objectSchema: objectSchema, db: db, cityfield: 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*/];
1905
1912
  }
1906
1913
  });
1907
1914
  };
@@ -1937,10 +1944,10 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1937
1944
  case 0:
1938
1945
  if (!(fldName == '_id')) return [3 /*break*/, 1];
1939
1946
  delete updateObj[fldName];
1940
- return [3 /*break*/, 5];
1947
+ return [3 /*break*/, 7];
1941
1948
  case 1:
1942
1949
  fieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fldName; });
1943
- if (!fieldSchema) return [3 /*break*/, 5];
1950
+ if (!fieldSchema) return [3 /*break*/, 7];
1944
1951
  cityfield = void 0;
1945
1952
  if (fieldSchema.LookupObject == "City") {
1946
1953
  cityfield = updateObj[fldName];
@@ -1968,7 +1975,14 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1968
1975
  case 4:
1969
1976
  _c.sent();
1970
1977
  _c.label = 5;
1971
- 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: fieldSchema, updateObj: updateObj, objectSchema: objectSchema, db: db, cityfield: 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*/];
1972
1986
  }
1973
1987
  });
1974
1988
  };
@@ -5669,17 +5683,27 @@ function SyncTotalSlotRemaining(registrationID, db) {
5669
5683
  });
5670
5684
  }
5671
5685
  exports.SyncTotalSlotRemaining = SyncTotalSlotRemaining;
5672
- function ValidateStateCountryField(fieldSchema, updateObj, fldName, objectSchema, db, cityfield) {
5686
+ /**
5687
+ *
5688
+ * @param param.fieldSchema fieldSchema contain field related schema information
5689
+ * @param param.updateObj updateObj contains the Updated Object data
5690
+ * @param param.objectSchema objectSchema contains the ObjectSchema of the Object
5691
+ * @param param.db database connection || Db
5692
+ * @param param.cityfield cityfield contain the City Id
5693
+ * @return return the updated State and Country field value based upon the City
5694
+ */
5695
+ function ValidateStateCountryField(_a) {
5696
+ var fieldSchema = _a.fieldSchema, updateObj = _a.updateObj, objectSchema = _a.objectSchema, db = _a.db, cityfield = _a.cityfield;
5673
5697
  return __awaiter(this, void 0, void 0, function () {
5674
5698
  var cityDocument, stateFieldSchema, countryFieldSchema, stateFieldSchema, countryFieldSchema;
5675
- return __generator(this, function (_a) {
5676
- switch (_a.label) {
5699
+ return __generator(this, function (_b) {
5700
+ switch (_b.label) {
5677
5701
  case 0:
5678
5702
  if (!((fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.LookupObject) === 'City')) return [3 /*break*/, 3];
5679
5703
  if (!cityfield) return [3 /*break*/, 2];
5680
5704
  return [4 /*yield*/, db.collection('City').findOne({ _id: cityfield })];
5681
5705
  case 1:
5682
- cityDocument = _a.sent();
5706
+ cityDocument = _b.sent();
5683
5707
  if (cityDocument) {
5684
5708
  stateFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.StateField; });
5685
5709
  if (fieldSchema.StateField && ['add', 'edit', 'both'].includes(stateFieldSchema.DisableON)) {
@@ -5700,7 +5724,7 @@ function ValidateStateCountryField(fieldSchema, updateObj, fldName, objectSchema
5700
5724
  if (fieldSchema.CountryField && ['add', 'edit', 'both'].includes(countryFieldSchema.DisableON)) {
5701
5725
  updateObj[fieldSchema.CountryField] = null;
5702
5726
  }
5703
- _a.label = 3;
5727
+ _b.label = 3;
5704
5728
  case 3: return [2 /*return*/];
5705
5729
  }
5706
5730
  });
@@ -1,4 +1,4 @@
1
- import { ObjectId } from "mongodb";
1
+ import { ObjectId, Db } from "mongodb";
2
2
  interface AnyObjectInterface {
3
3
  [key: string]: any;
4
4
  }
@@ -14,4 +14,11 @@ interface GetEncryptedURLOptions {
14
14
  fieldName: string;
15
15
  filterKey: string;
16
16
  }
17
- export { AnyObjectInterface, callBackInterface, GetEncryptedURLOptions };
17
+ interface ValidateStateCountryOptions {
18
+ fieldSchema: AnyObjectInterface;
19
+ updateObj: AnyObjectInterface;
20
+ objectSchema: AnyObjectInterface;
21
+ db: Db;
22
+ cityfield: AnyObjectInterface;
23
+ }
24
+ export { AnyObjectInterface, callBackInterface, GetEncryptedURLOptions, ValidateStateCountryOptions };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.383",
3
+ "version": "1.0.384",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {