@optimiser/common 1.0.380 → 1.0.382

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
1863
  if (!fieldSchema) return [3 /*break*/, 7];
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:
@@ -1927,7 +1931,7 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1927
1931
  switch (_b.label) {
1928
1932
  case 0:
1929
1933
  _loop_12 = function (fldName) {
1930
- var fieldSchema, oldValue, newValue, isSame;
1934
+ var fieldSchema, cityfield, oldValue, newValue, isSame;
1931
1935
  return __generator(this, function (_c) {
1932
1936
  switch (_c.label) {
1933
1937
  case 0:
@@ -1937,6 +1941,10 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1937
1941
  case 1:
1938
1942
  fieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fldName; });
1939
1943
  if (!fieldSchema) return [3 /*break*/, 5];
1944
+ cityfield = void 0;
1945
+ if (fieldSchema.LookupObject == "City") {
1946
+ cityfield = updateObj[fldName];
1947
+ }
1940
1948
  if (!(fieldSchema.UIDataType == 'autoincrement' || fieldSchema.UIDataType == 'formula')) return [3 /*break*/, 2];
1941
1949
  delete updateObj[fldName];
1942
1950
  return [3 /*break*/, 5];
@@ -4781,13 +4789,13 @@ function ValidateUserInput(options) {
4781
4789
  }
4782
4790
  field = schemaFields.find(function (x) { return x.Name == fieldName; });
4783
4791
  if (!field) return [3 /*break*/, 58];
4784
- if (field.DisableValidateUserInput) {
4785
- return [2 /*return*/, "continue"];
4786
- }
4787
4792
  if (IsStringValue(fieldData)) { //sanitizing Html
4788
4793
  inputFields[fieldName] = (0, sanitize_html_1.default)(fieldData);
4789
4794
  fieldData = inputFields[fieldName];
4790
4795
  }
4796
+ if (field.DisableValidateUserInput) {
4797
+ return [2 /*return*/, "continue"];
4798
+ }
4791
4799
  if ((field.UIDataType == 'date' || field.UIDataType == 'datetime') && IsStringValue(fieldData) && fieldData.trim() == '') {
4792
4800
  inputFields[fieldName] = null;
4793
4801
  }
@@ -5660,3 +5668,40 @@ function SyncTotalSlotRemaining(registrationID, db) {
5660
5668
  });
5661
5669
  }
5662
5670
  exports.SyncTotalSlotRemaining = SyncTotalSlotRemaining;
5671
+ function ValidateStateCountryField(fieldSchema, updateObj, fldName, objectSchema, db, cityfield) {
5672
+ return __awaiter(this, void 0, void 0, function () {
5673
+ var cityDocument, stateFieldSchema, countryFieldSchema, stateFieldSchema, countryFieldSchema;
5674
+ return __generator(this, function (_a) {
5675
+ switch (_a.label) {
5676
+ case 0:
5677
+ if (!((fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.LookupObject) === 'City')) return [3 /*break*/, 3];
5678
+ if (!cityfield) return [3 /*break*/, 2];
5679
+ return [4 /*yield*/, db.collection('City').findOne({ _id: updateObj[fldName] })];
5680
+ case 1:
5681
+ cityDocument = _a.sent();
5682
+ if (cityDocument) {
5683
+ stateFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.StateField; });
5684
+ if (fieldSchema.StateField && ['add', 'edit', 'both'].includes(stateFieldSchema.DisableON)) {
5685
+ updateObj[fieldSchema.StateField] = cityDocument.State;
5686
+ }
5687
+ countryFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.CountryField; });
5688
+ if (fieldSchema.CountryField && ['add', 'edit', 'both'].includes(countryFieldSchema.DisableON)) {
5689
+ updateObj[fieldSchema.CountryField] = cityDocument.CountryID;
5690
+ }
5691
+ }
5692
+ return [3 /*break*/, 3];
5693
+ case 2:
5694
+ stateFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.StateField; });
5695
+ if (fieldSchema.StateField && ['add', 'edit', 'both'].includes(stateFieldSchema.DisableON)) {
5696
+ updateObj[fieldSchema.StateField] = null;
5697
+ }
5698
+ countryFieldSchema = objectSchema.Fields.find(function (x) { return x.Name == fieldSchema.CountryField; });
5699
+ if (fieldSchema.CountryField && ['add', 'edit', 'both'].includes(countryFieldSchema.DisableON)) {
5700
+ updateObj[fieldSchema.CountryField] = null;
5701
+ }
5702
+ _a.label = 3;
5703
+ case 3: return [2 /*return*/];
5704
+ }
5705
+ });
5706
+ });
5707
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.380",
3
+ "version": "1.0.382",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {