@optimiser/common 1.0.425 → 1.0.427

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 (2) hide show
  1. package/dist/lib/utility.js +184 -123
  2. package/package.json +59 -59
@@ -1580,24 +1580,24 @@ exports.GetObjectByString = GetObjectByString;
1580
1580
  function BuildLookupDataField(fieldSchema, updateObj, db) {
1581
1581
  var _a, _b;
1582
1582
  return __awaiter(this, void 0, void 0, function () {
1583
- var fldValue, fldName, alias, searchAlias, fldLookupData, aggregateArry, project, i, obj, lookupObj, i, i, data, _c, result, _loop_10, j, i, unionDetail, unionPipeline, unionObj, result, i, lookupRecord, j, result, j, result, i, lookupRecord, j, result, i, lookupRecord, error_2, fieldValueType, errMsg;
1583
+ var fldValue, fldName_2, alias, searchAlias, fldLookupData, aggregateArry, project_1, i, obj, lookupObj, i, i, data, _c, result, _loop_10, j, i, unionDetail, unionPipeline, unionObj, result, i, lookupRecord, j, result, j, result, i, lookupRecord, j, result, i, lookupRecord, fetchFileData, video_Id, thumbnail_Id, error_2, fieldValueType, errMsg;
1584
1584
  return __generator(this, function (_d) {
1585
1585
  switch (_d.label) {
1586
1586
  case 0:
1587
1587
  fldValue = null;
1588
1588
  _d.label = 1;
1589
1589
  case 1:
1590
- _d.trys.push([1, 23, , 24]);
1591
- if (!fieldSchema.UIDataType) return [3 /*break*/, 22];
1592
- fldName = fieldSchema.Name;
1593
- fldValue = updateObj[fldName];
1594
- if (!constants_1.default.LookupTypeFields.includes(fieldSchema.UIDataType)) return [3 /*break*/, 22];
1595
- alias = fldName + constants_1.default.LookupAlias;
1596
- searchAlias = fldName + constants_1.default.SearchValueAlias;
1590
+ _d.trys.push([1, 24, , 25]);
1591
+ if (!fieldSchema.UIDataType) return [3 /*break*/, 23];
1592
+ fldName_2 = fieldSchema.Name;
1593
+ fldValue = updateObj[fldName_2];
1594
+ if (!constants_1.default.LookupTypeFields.includes(fieldSchema.UIDataType)) return [3 /*break*/, 23];
1595
+ alias = fldName_2 + constants_1.default.LookupAlias;
1596
+ searchAlias = fldName_2 + constants_1.default.SearchValueAlias;
1597
1597
  fldLookupData = null;
1598
- if (!fldValue) return [3 /*break*/, 21];
1598
+ if (!fldValue) return [3 /*break*/, 22];
1599
1599
  aggregateArry = [];
1600
- project = { '_id': 1, IsActive: 1 };
1600
+ project_1 = { '_id': 1, IsActive: 1 };
1601
1601
  if (fieldSchema.ExtraLookupObjects) {
1602
1602
  for (i = 0; i < fieldSchema.ExtraLookupObjects.length; i++) {
1603
1603
  obj = fieldSchema.ExtraLookupObjects[i];
@@ -1608,19 +1608,19 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1608
1608
  lookupObj["as"] = obj.as;
1609
1609
  aggregateArry.push({ $lookup: lookupObj });
1610
1610
  aggregateArry.push({ $unwind: { path: '$' + obj.as, preserveNullAndEmptyArrays: true } });
1611
- project[obj.as + '._id'] = 1;
1612
- project[obj.as + '.IsActive'] = 1;
1611
+ project_1[obj.as + '._id'] = 1;
1612
+ project_1[obj.as + '.IsActive'] = 1;
1613
1613
  }
1614
1614
  }
1615
1615
  if (fieldSchema.LookupFields != undefined) {
1616
1616
  for (i = 0; i < fieldSchema.LookupFields.length; i++) {
1617
- project[fieldSchema.LookupFields[i]] = 1;
1617
+ project_1[fieldSchema.LookupFields[i]] = 1;
1618
1618
  }
1619
1619
  ;
1620
1620
  }
1621
1621
  if (fieldSchema.ExtraLookupFields != undefined) {
1622
1622
  for (i = 0; i < fieldSchema.ExtraLookupFields.length; i++) {
1623
- project[fieldSchema.ExtraLookupFields[i]] = 1;
1623
+ project_1[fieldSchema.ExtraLookupFields[i]] = 1;
1624
1624
  }
1625
1625
  ;
1626
1626
  }
@@ -1633,11 +1633,12 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1633
1633
  case "multiselect": return [3 /*break*/, 11];
1634
1634
  case "file": return [3 /*break*/, 16];
1635
1635
  case "image": return [3 /*break*/, 16];
1636
+ case "video": return [3 /*break*/, 19];
1636
1637
  }
1637
- return [3 /*break*/, 19];
1638
+ return [3 /*break*/, 20];
1638
1639
  case 2:
1639
1640
  aggregateArry.push({ $match: { '_id': fldValue } });
1640
- aggregateArry.push({ $project: project });
1641
+ aggregateArry.push({ $project: project_1 });
1641
1642
  return [4 /*yield*/, db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray()];
1642
1643
  case 3:
1643
1644
  // db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
@@ -1667,10 +1668,10 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1667
1668
  }
1668
1669
  // resolve()
1669
1670
  // });
1670
- return [3 /*break*/, 20];
1671
+ return [3 /*break*/, 21];
1671
1672
  case 4:
1672
1673
  aggregateArry.push({ $match: { '_id': { $in: fldValue } } });
1673
- aggregateArry.push({ $project: project });
1674
+ aggregateArry.push({ $project: project_1 });
1674
1675
  if (fieldSchema.UnionWith && fieldSchema.UnionWith.length > 0) {
1675
1676
  for (i = 0; i < fieldSchema.UnionWith.length; i++) {
1676
1677
  unionDetail = fieldSchema.UnionWith[i];
@@ -1679,7 +1680,7 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1679
1680
  unionPipeline.push({
1680
1681
  $match: { '_id': { $in: fldValue } }
1681
1682
  });
1682
- unionPipeline.push({ $project: project });
1683
+ unionPipeline.push({ $project: project_1 });
1683
1684
  unionObj = { coll: unionDetail.LookupObject, pipeline: unionPipeline };
1684
1685
  aggregateArry.push({ $unionWith: unionObj });
1685
1686
  }
@@ -1711,11 +1712,11 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1711
1712
  }
1712
1713
  // resolve()
1713
1714
  // });
1714
- return [3 /*break*/, 20];
1715
+ return [3 /*break*/, 21];
1715
1716
  case 6:
1716
1717
  if (!fieldSchema.LookupObject) return [3 /*break*/, 8];
1717
1718
  aggregateArry.push({ $match: { _id: fldValue } });
1718
- aggregateArry.push({ $project: project });
1719
+ aggregateArry.push({ $project: project_1 });
1719
1720
  return [4 /*yield*/, db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray()];
1720
1721
  case 7:
1721
1722
  // db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
@@ -1763,11 +1764,11 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1763
1764
  //** Ends here */
1764
1765
  }
1765
1766
  _d.label = 10;
1766
- case 10: return [3 /*break*/, 20];
1767
+ case 10: return [3 /*break*/, 21];
1767
1768
  case 11:
1768
1769
  if (!fieldSchema.LookupObject) return [3 /*break*/, 13];
1769
1770
  aggregateArry.push({ $match: { '_id': { $in: fldValue } } });
1770
- aggregateArry.push({ $project: project });
1771
+ aggregateArry.push({ $project: project_1 });
1771
1772
  return [4 /*yield*/, db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray()];
1772
1773
  case 12:
1773
1774
  // db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
@@ -1818,12 +1819,12 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1818
1819
  //** Ends here */
1819
1820
  }
1820
1821
  _d.label = 15;
1821
- case 15: return [3 /*break*/, 20];
1822
+ case 15: return [3 /*break*/, 21];
1822
1823
  case 16:
1823
1824
  if (!!fieldSchema.IsMultiple) return [3 /*break*/, 18];
1824
1825
  aggregateArry.push({ $match: { '_id': fldValue } });
1825
- project['FileName'] = 1;
1826
- aggregateArry.push({ $project: project });
1826
+ project_1['FileName'] = 1;
1827
+ aggregateArry.push({ $project: project_1 });
1827
1828
  return [4 /*yield*/, db.collection('Drive').aggregate(aggregateArry).toArray()];
1828
1829
  case 17:
1829
1830
  // db.collection('Drive').aggregate(aggregateArry).toArray(function (err: Error, data: AnyObjectInterface[]) {
@@ -1841,20 +1842,57 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1841
1842
  // else {
1842
1843
  // resolve();
1843
1844
  // }
1844
- return [3 /*break*/, 20];
1845
- case 19:
1845
+ return [3 /*break*/, 21];
1846
+ case 19:
1847
+ {
1848
+ // // Remove previous lookup data
1849
+ delete updateObj[fldName_2]['VideoFile_LookupData'];
1850
+ delete updateObj[fldName_2]['ThumbnailImage_LookupData'];
1851
+ fetchFileData = function (fileId, includeDuration) {
1852
+ if (!fileId)
1853
+ return Promise.resolve([]);
1854
+ var projectQuery = __assign(__assign({}, project_1), { FileName: 1 }); // Keep existing values
1855
+ if (includeDuration) {
1856
+ projectQuery['Duration'] = 1;
1857
+ }
1858
+ return db.collection('Drive').aggregate([
1859
+ { $match: { _id: fileId } },
1860
+ { $project: projectQuery }
1861
+ ]).toArray();
1862
+ };
1863
+ video_Id = fldValue["VideoFile"];
1864
+ thumbnail_Id = fldValue["ThumbnailImage"];
1865
+ Promise.all([
1866
+ fetchFileData(video_Id !== null && video_Id !== void 0 ? video_Id : "", true),
1867
+ fetchFileData(thumbnail_Id !== null && thumbnail_Id !== void 0 ? thumbnail_Id : "", false)
1868
+ ])
1869
+ .then(function (_a) {
1870
+ var videoData = _a[0], thumbnailData = _a[1];
1871
+ if (videoData.length > 0) {
1872
+ updateObj[fldName_2]['VideoFile_LookupData'] = videoData[0];
1873
+ }
1874
+ if (thumbnailData.length > 0) {
1875
+ updateObj[fldName_2]['ThumbnailImage_LookupData'] = thumbnailData[0];
1876
+ }
1877
+ })
1878
+ .catch(function (error) {
1879
+ console.error("Error in Video Upload Process:", error);
1880
+ });
1881
+ }
1882
+ return [3 /*break*/, 21];
1883
+ case 20:
1846
1884
  // resolve()
1847
- return [3 /*break*/, 20];
1848
- case 20: return [3 /*break*/, 22];
1849
- case 21:
1885
+ return [3 /*break*/, 21];
1886
+ case 21: return [3 /*break*/, 23];
1887
+ case 22:
1850
1888
  updateObj[alias] = fldLookupData;
1851
1889
  // Below if cond was added by Shahzaib on 05/09/2022
1852
1890
  if (['dropdown', 'lookup', 'multilookup', 'multiselect'].includes(fieldSchema.UIDataType)) {
1853
1891
  updateObj[searchAlias] = "";
1854
1892
  }
1855
- _d.label = 22;
1856
- case 22: return [3 /*break*/, 24];
1857
- case 23:
1893
+ _d.label = 23;
1894
+ case 23: return [3 /*break*/, 25];
1895
+ case 24:
1858
1896
  error_2 = _d.sent();
1859
1897
  fieldValueType = (Array.isArray(fldValue) ? 'array' : '');
1860
1898
  if (!fieldValueType) {
@@ -1862,8 +1900,8 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1862
1900
  }
1863
1901
  errMsg = "Error Info: Error in Function BuildLookupDataField in Common Module for Company - ".concat((db.databaseName), ", ObjectName - ").concat(((fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.LookupObject) || ''), ", FieldName - ").concat(((fieldSchema === null || fieldSchema === void 0 ? void 0 : fieldSchema.Name) || ''), " for value - ").concat(fldValue, " and data type of values is ").concat((fieldValueType || ''), " ");
1864
1902
  console.error(errMsg, '\n', error_2);
1865
- return [3 /*break*/, 24];
1866
- case 24: return [2 /*return*/];
1903
+ return [3 /*break*/, 25];
1904
+ case 25: return [2 /*return*/];
1867
1905
  }
1868
1906
  });
1869
1907
  });
@@ -4846,29 +4884,31 @@ function ValidateUserInput(options) {
4846
4884
  break;
4847
4885
  }
4848
4886
  }
4849
- for (_d = 0, _e = pageData.Groups; _d < _e.length; _d++) {
4850
- grp = _e[_d];
4851
- if (grp.IsConditionalGroup) {
4852
- _loop_19 = function (fld) {
4853
- fld = JSON.parse(JSON.stringify(fld));
4854
- var schemafld = schemaFields.find(function (x) { return x.Name == fld.Name; });
4855
- fld.Schema = schemafld;
4856
- msg = CheckConditionalGroup(grp, fld, fieldsJsonData);
4857
- if (msg != "")
4858
- return "break";
4859
- };
4860
- for (_f = 0, _g = grp.Fields; _f < _g.length; _f++) {
4861
- fld = _g[_f];
4862
- state_2 = _loop_19(fld);
4863
- if (state_2 === "break")
4864
- break;
4887
+ if (pageData.Groups && pageData.Groups.length) {
4888
+ for (_d = 0, _e = pageData.Groups; _d < _e.length; _d++) {
4889
+ grp = _e[_d];
4890
+ if (grp.IsConditionalGroup) {
4891
+ _loop_19 = function (fld) {
4892
+ fld = JSON.parse(JSON.stringify(fld));
4893
+ var schemafld = schemaFields.find(function (x) { return x.Name == fld.Name; });
4894
+ fld.Schema = schemafld;
4895
+ msg = CheckConditionalGroup(grp, fld, fieldsJsonData);
4896
+ if (msg != "")
4897
+ return "break";
4898
+ };
4899
+ for (_f = 0, _g = grp.Fields; _f < _g.length; _f++) {
4900
+ fld = _g[_f];
4901
+ state_2 = _loop_19(fld);
4902
+ if (state_2 === "break")
4903
+ break;
4904
+ }
4865
4905
  }
4866
4906
  }
4867
4907
  }
4868
4908
  _loop_20 = function (pageField) {
4869
- var fieldName, fieldData, field, parentData, oldValue, newValue, isSame, searchQuery, result, fld, _k, minValue, maxValue, filter, searchObj, dbConnection, result, searchObj, totalRecord, _l, schemaData, result, searchObj, result, schemaData, result, searchObj, totalRecord, regexpression, phone, files, _m, fieldData_1, obj, searchObj, totalRecord, searchObj, result, _o, fieldData_2, obj;
4870
- return __generator(this, function (_p) {
4871
- switch (_p.label) {
4909
+ var fieldName, fieldData, field, parentData, oldValue, newValue, isSame, searchQuery, result, fld, _k, minValue, maxValue, filter, searchObj, dbConnection, result, searchObj, totalRecord, _l, schemaData, result, searchObj, result, schemaData, result, searchObj, totalRecord, regexpression, phone, files, _m, fieldData_1, obj, searchObj, totalRecord, searchObj, result, searchVideoObj, searchThumbnailObj, _o, videoResult, thumbnailResult, _p, fieldData_2, obj;
4910
+ return __generator(this, function (_q) {
4911
+ switch (_q.label) {
4872
4912
  case 0:
4873
4913
  if (msg != "") {
4874
4914
  return [2 /*return*/, "break"];
@@ -4879,7 +4919,7 @@ function ValidateUserInput(options) {
4879
4919
  delete inputFields[pageField.Name];
4880
4920
  }
4881
4921
  field = schemaFields.find(function (x) { return x.Name == fieldName; });
4882
- if (!field) return [3 /*break*/, 58];
4922
+ if (!field) return [3 /*break*/, 60];
4883
4923
  //sanitizing Html and added IgnoreSanitizeHtml condition so that it can be ignored for certain fields
4884
4924
  if (!field.IgnoreSanitizeHtml && IsStringValue(fieldData)) {
4885
4925
  inputFields[fieldName] = CustomSanitizeHtml(fieldData, field.UIDataType);
@@ -4914,7 +4954,7 @@ function ValidateUserInput(options) {
4914
4954
  if (!(action === 'update' && (['edit', 'both'].includes(field.DisableON) || ['edit', 'both'].includes(field.HideON)))) return [3 /*break*/, 3];
4915
4955
  return [4 /*yield*/, db.collection(objectName).findOne({ '_id': documentID })];
4916
4956
  case 2:
4917
- parentData = _p.sent();
4957
+ parentData = _q.sent();
4918
4958
  oldValue = parentData[fieldName] != undefined ? parentData[fieldName] : null;
4919
4959
  newValue = fieldData;
4920
4960
  // Check if newValue is undefined
@@ -4932,7 +4972,7 @@ function ValidateUserInput(options) {
4932
4972
  msg = "The field " + field.DisplayName + " was passed in the API request but is not allowed.";
4933
4973
  return [2 /*return*/, "break"];
4934
4974
  }
4935
- _p.label = 3;
4975
+ _q.label = 3;
4936
4976
  case 3:
4937
4977
  if (!(field.IsUnique == true)) return [3 /*break*/, 5];
4938
4978
  if (!(field.UIDataType == "email" && fieldData)) return [3 /*break*/, 5];
@@ -4943,12 +4983,12 @@ function ValidateUserInput(options) {
4943
4983
  }
4944
4984
  return [4 /*yield*/, db.collection(objectSchema.Name).findOne(searchQuery)];
4945
4985
  case 4:
4946
- result = _p.sent();
4986
+ result = _q.sent();
4947
4987
  if (result != null) {
4948
4988
  msg = 'Email already exists for ' + field.DisplayName + '!';
4949
4989
  return [2 /*return*/, "break"];
4950
4990
  }
4951
- _p.label = 5;
4991
+ _q.label = 5;
4952
4992
  case 5:
4953
4993
  // Added by Shahzaib to check conditional field criteria
4954
4994
  if (field.IsConditionalField) {
@@ -4958,8 +4998,8 @@ function ValidateUserInput(options) {
4958
4998
  if (msg != "")
4959
4999
  return [2 /*return*/, "break"];
4960
5000
  }
4961
- if (!inputField.includes(fieldName)) return [3 /*break*/, 57];
4962
- if (!(fieldData || fieldData === 0 || fieldData === false)) return [3 /*break*/, 57];
5001
+ if (!inputField.includes(fieldName)) return [3 /*break*/, 59];
5002
+ if (!(fieldData || fieldData === 0 || fieldData === false)) return [3 /*break*/, 59];
4963
5003
  _k = field.UIDataType;
4964
5004
  switch (_k) {
4965
5005
  case 'int': return [3 /*break*/, 6];
@@ -4977,12 +5017,13 @@ function ValidateUserInput(options) {
4977
5017
  case 'phone': return [3 /*break*/, 41];
4978
5018
  case "image": return [3 /*break*/, 42];
4979
5019
  case 'file': return [3 /*break*/, 42];
4980
- case 'textarea': return [3 /*break*/, 51];
4981
- case 'text': return [3 /*break*/, 51];
4982
- case 'texteditor': return [3 /*break*/, 51];
4983
- case 'collection': return [3 /*break*/, 52];
5020
+ case 'video': return [3 /*break*/, 51];
5021
+ case 'textarea': return [3 /*break*/, 53];
5022
+ case 'text': return [3 /*break*/, 53];
5023
+ case 'texteditor': return [3 /*break*/, 53];
5024
+ case 'collection': return [3 /*break*/, 54];
4984
5025
  }
4985
- return [3 /*break*/, 57];
5026
+ return [3 /*break*/, 59];
4986
5027
  case 6:
4987
5028
  {
4988
5029
  if (IsStringValue(fieldData) || Number.isInteger(fieldData) == false) {
@@ -4995,7 +5036,7 @@ function ValidateUserInput(options) {
4995
5036
  msg = field.DisplayName + ' value must be smaller then or equal to ' + field.MaxValue;
4996
5037
  }
4997
5038
  }
4998
- return [3 /*break*/, 57];
5039
+ return [3 /*break*/, 59];
4999
5040
  case 7:
5000
5041
  {
5001
5042
  minValue = field.MinValue, maxValue = field.MaxValue;
@@ -5013,14 +5054,14 @@ function ValidateUserInput(options) {
5013
5054
  msg = field.DisplayName + ' value must be smaller then or equal to ' + maxValue;
5014
5055
  }
5015
5056
  }
5016
- return [3 /*break*/, 57];
5057
+ return [3 /*break*/, 59];
5017
5058
  case 8:
5018
5059
  {
5019
5060
  if ((fieldData instanceof Date && !isNaN(inputFields[fieldName])) == false) {
5020
5061
  msg = 'Invalid date for ' + field.DisplayName + '!';
5021
5062
  }
5022
5063
  }
5023
- return [3 /*break*/, 57];
5064
+ return [3 /*break*/, 59];
5024
5065
  case 9:
5025
5066
  {
5026
5067
  if (field.ShowNextDayHoursUpto) {
@@ -5038,7 +5079,7 @@ function ValidateUserInput(options) {
5038
5079
  }
5039
5080
  }
5040
5081
  }
5041
- return [3 /*break*/, 57];
5082
+ return [3 /*break*/, 59];
5042
5083
  case 10:
5043
5084
  {
5044
5085
  filter = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})$/;
@@ -5046,14 +5087,14 @@ function ValidateUserInput(options) {
5046
5087
  msg = fieldData + ' is invalid email for ' + field.DisplayName + '!';
5047
5088
  }
5048
5089
  }
5049
- return [3 /*break*/, 57];
5090
+ return [3 /*break*/, 59];
5050
5091
  case 11:
5051
5092
  {
5052
5093
  if (fieldData !== true && fieldData !== false) {
5053
5094
  msg = 'Invalid user input for ' + field.DisplayName + '!';
5054
5095
  }
5055
5096
  }
5056
- return [3 /*break*/, 57];
5097
+ return [3 /*break*/, 59];
5057
5098
  case 12:
5058
5099
  if (!!field.IsMultipleLookupObject) return [3 /*break*/, 14];
5059
5100
  searchObj = { _id: fieldData };
@@ -5068,12 +5109,12 @@ function ValidateUserInput(options) {
5068
5109
  dbConnection = (field.UseMasterDatabase && mdb) ? mdb : db;
5069
5110
  return [4 /*yield*/, dbConnection.collection(field.LookupObject).findOne(searchObj)];
5070
5111
  case 13:
5071
- result = _p.sent();
5112
+ result = _q.sent();
5072
5113
  if (result == null) {
5073
5114
  msg = field.DisplayName + ' does not exist!';
5074
5115
  }
5075
- _p.label = 14;
5076
- case 14: return [3 /*break*/, 57];
5116
+ _q.label = 14;
5117
+ case 14: return [3 /*break*/, 59];
5077
5118
  case 15:
5078
5119
  if (!Array.isArray(fieldData)) return [3 /*break*/, 22];
5079
5120
  if (!fieldData.length) return [3 /*break*/, 20];
@@ -5089,42 +5130,42 @@ function ValidateUserInput(options) {
5089
5130
  ;
5090
5131
  return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
5091
5132
  case 16:
5092
- totalRecord = _p.sent();
5133
+ totalRecord = _q.sent();
5093
5134
  if (!(objectName == "Activity" && field.Name == 'Attendees')) return [3 /*break*/, 18];
5094
5135
  _l = totalRecord;
5095
5136
  return [4 /*yield*/, db.collection('Contact').find(searchObj).count()];
5096
5137
  case 17:
5097
- totalRecord = _l + _p.sent();
5098
- _p.label = 18;
5138
+ totalRecord = _l + _q.sent();
5139
+ _q.label = 18;
5099
5140
  case 18:
5100
5141
  if (totalRecord !== fieldData.length) {
5101
5142
  msg = field.DisplayName + ' does not exist!';
5102
5143
  }
5103
- _p.label = 19;
5144
+ _q.label = 19;
5104
5145
  case 19: return [3 /*break*/, 21];
5105
5146
  case 20:
5106
5147
  if (field.IsRequired) {
5107
5148
  msg = field.DisplayName + ' is required!';
5108
5149
  }
5109
- _p.label = 21;
5150
+ _q.label = 21;
5110
5151
  case 21: return [3 /*break*/, 23];
5111
5152
  case 22:
5112
5153
  msg = 'Invalid value for ' + field.DisplayName;
5113
- _p.label = 23;
5114
- case 23: return [3 /*break*/, 57];
5154
+ _q.label = 23;
5155
+ case 23: return [3 /*break*/, 59];
5115
5156
  case 24:
5116
5157
  if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 27];
5117
5158
  if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 26];
5118
5159
  schemaData = null;
5119
5160
  return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
5120
5161
  case 25:
5121
- result = _p.sent();
5162
+ result = _q.sent();
5122
5163
  if (result && result.Data)
5123
5164
  schemaData = result.Data.find(function (x) { return x.Key == fieldData; });
5124
5165
  if (schemaData == null || (action == 'add' && schemaData.IsActive == false)) {
5125
5166
  msg = field.DisplayName + ' does not exist!';
5126
5167
  }
5127
- _p.label = 26;
5168
+ _q.label = 26;
5128
5169
  case 26: return [3 /*break*/, 29];
5129
5170
  case 27:
5130
5171
  if (!(field.LookupObject !== undefined && !field.IsMultipleLookupObject)) return [3 /*break*/, 29];
@@ -5139,12 +5180,12 @@ function ValidateUserInput(options) {
5139
5180
  ;
5140
5181
  return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
5141
5182
  case 28:
5142
- result = _p.sent();
5183
+ result = _q.sent();
5143
5184
  if (result == null) {
5144
5185
  msg = field.DisplayName + ' does not exist!';
5145
5186
  }
5146
- _p.label = 29;
5147
- case 29: return [3 /*break*/, 57];
5187
+ _q.label = 29;
5188
+ case 29: return [3 /*break*/, 59];
5148
5189
  case 30:
5149
5190
  if (!Array.isArray(fieldData)) return [3 /*break*/, 38];
5150
5191
  if (!fieldData.length) return [3 /*break*/, 36];
@@ -5153,7 +5194,7 @@ function ValidateUserInput(options) {
5153
5194
  schemaData = [];
5154
5195
  return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
5155
5196
  case 31:
5156
- result = _p.sent();
5197
+ result = _q.sent();
5157
5198
  if (result && result.Data) {
5158
5199
  if (action == 'add')
5159
5200
  schemaData = result.Data.filter(function (x) { return x.IsActive == true && fieldData.includes(x.Key.toString()); });
@@ -5163,7 +5204,7 @@ function ValidateUserInput(options) {
5163
5204
  if (schemaData.length != fieldData.length) {
5164
5205
  msg = field.DisplayName + ' does not exist!';
5165
5206
  }
5166
- _p.label = 32;
5207
+ _q.label = 32;
5167
5208
  case 32: return [3 /*break*/, 35];
5168
5209
  case 33:
5169
5210
  if (!(field.LookupObject !== undefined && !field.IsMultipleLookupObject)) return [3 /*break*/, 35];
@@ -5178,22 +5219,22 @@ function ValidateUserInput(options) {
5178
5219
  ;
5179
5220
  return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
5180
5221
  case 34:
5181
- totalRecord = _p.sent();
5222
+ totalRecord = _q.sent();
5182
5223
  if (totalRecord !== fieldData.length) {
5183
5224
  msg = field.DisplayName + ' does not exist!';
5184
5225
  }
5185
- _p.label = 35;
5226
+ _q.label = 35;
5186
5227
  case 35: return [3 /*break*/, 37];
5187
5228
  case 36:
5188
5229
  if (field.IsRequired) {
5189
5230
  msg = field.DisplayName + ' is required!';
5190
5231
  }
5191
- _p.label = 37;
5232
+ _q.label = 37;
5192
5233
  case 37: return [3 /*break*/, 39];
5193
5234
  case 38:
5194
5235
  msg = 'Invalid value for ' + field.DisplayName;
5195
- _p.label = 39;
5196
- case 39: return [3 /*break*/, 57];
5236
+ _q.label = 39;
5237
+ case 39: return [3 /*break*/, 59];
5197
5238
  case 40:
5198
5239
  {
5199
5240
  regexpression = new RegExp('^(https?:\\/\\/)?((([a-z\\d]([a-z\\d-]*[a-z\\d])*)\\.)+[a-z]{2,}|((\\d{1,3}\\.){3}\\d{1,3}))(\\:\\d+)?(\\/[-a-z\\d%_.~+@,:=#()]*)*(\\?[;&a-z\\d%_@,.:()~+=-]*)?(\\#[-a-z\\d_]*)?$', 'i');
@@ -5201,7 +5242,7 @@ function ValidateUserInput(options) {
5201
5242
  msg = 'Invalid URL for ' + field.DisplayName + '!';
5202
5243
  }
5203
5244
  }
5204
- return [3 /*break*/, 57];
5245
+ return [3 /*break*/, 59];
5205
5246
  case 41:
5206
5247
  {
5207
5248
  if (field.IncludeCountryCode) {
@@ -5216,7 +5257,7 @@ function ValidateUserInput(options) {
5216
5257
  }
5217
5258
  }
5218
5259
  }
5219
- return [3 /*break*/, 57];
5260
+ return [3 /*break*/, 59];
5220
5261
  case 42:
5221
5262
  if (!field.IsMultiple) return [3 /*break*/, 48];
5222
5263
  if (!Array.isArray(fieldData)) return [3 /*break*/, 46];
@@ -5233,7 +5274,7 @@ function ValidateUserInput(options) {
5233
5274
  ;
5234
5275
  return [4 /*yield*/, db.collection("Drive").find(searchObj).count()];
5235
5276
  case 43:
5236
- totalRecord = _p.sent();
5277
+ totalRecord = _q.sent();
5237
5278
  if (totalRecord !== fieldData.length) {
5238
5279
  msg = field.DisplayName + ' does not exist!';
5239
5280
  }
@@ -5242,11 +5283,11 @@ function ValidateUserInput(options) {
5242
5283
  if (field.IsRequired) {
5243
5284
  msg = field.DisplayName + ' is required!';
5244
5285
  }
5245
- _p.label = 45;
5286
+ _q.label = 45;
5246
5287
  case 45: return [3 /*break*/, 47];
5247
5288
  case 46:
5248
5289
  msg = 'Invalid value for ' + field.DisplayName;
5249
- _p.label = 47;
5290
+ _q.label = 47;
5250
5291
  case 47: return [3 /*break*/, 50];
5251
5292
  case 48:
5252
5293
  searchObj = { _id: fieldData };
@@ -5256,13 +5297,33 @@ function ValidateUserInput(options) {
5256
5297
  ;
5257
5298
  return [4 /*yield*/, db.collection("Drive").findOne(searchObj)];
5258
5299
  case 49:
5259
- result = _p.sent();
5300
+ result = _q.sent();
5260
5301
  if (result == null) {
5261
5302
  msg = field.DisplayName + ' does not exist!';
5262
5303
  }
5263
- _p.label = 50;
5264
- case 50: return [3 /*break*/, 57];
5304
+ _q.label = 50;
5305
+ case 50: return [3 /*break*/, 59];
5265
5306
  case 51:
5307
+ searchVideoObj = { _id: fieldData['VideoFile'] };
5308
+ searchThumbnailObj = { _id: fieldData['ThumbnailImage'] };
5309
+ if (action === 'add') {
5310
+ searchVideoObj.IsActive = true;
5311
+ searchThumbnailObj.IsActive = true;
5312
+ }
5313
+ return [4 /*yield*/, Promise.all([
5314
+ db.collection("Drive").findOne(searchVideoObj),
5315
+ db.collection("Drive").findOne(searchThumbnailObj)
5316
+ ])];
5317
+ case 52:
5318
+ _o = _q.sent(), videoResult = _o[0], thumbnailResult = _o[1];
5319
+ if (!videoResult) {
5320
+ msg = field.DisplayName + ' (VideoFile) does not exist!';
5321
+ }
5322
+ if (!thumbnailResult) {
5323
+ msg += (msg ? ' ' : '') + field.DisplayName + ' (ThumbnailImage) does not exist!';
5324
+ }
5325
+ return [3 /*break*/, 59];
5326
+ case 53:
5266
5327
  {
5267
5328
  // Maxlength check;
5268
5329
  if (field.MaxLength !== undefined && field.MaxLength !== null && fieldData.length > field.MaxLength) {
@@ -5272,34 +5333,34 @@ function ValidateUserInput(options) {
5272
5333
  msg = 'Invalid value for ' + field.DisplayName;
5273
5334
  }
5274
5335
  }
5275
- return [3 /*break*/, 57];
5276
- case 52:
5277
- if (!fieldData.length) return [3 /*break*/, 56];
5278
- _o = 0, fieldData_2 = fieldData;
5279
- _p.label = 53;
5280
- case 53:
5281
- if (!(_o < fieldData_2.length)) return [3 /*break*/, 56];
5282
- obj = fieldData_2[_o];
5283
- return [4 /*yield*/, ValidateUserInput({ 'userInput': obj, 'pageData': pageData, 'objectID': documentID, 'db': db, 'collectionField': fieldName })];
5336
+ return [3 /*break*/, 59];
5284
5337
  case 54:
5285
- validateResp = _p.sent();
5338
+ if (!fieldData.length) return [3 /*break*/, 58];
5339
+ _p = 0, fieldData_2 = fieldData;
5340
+ _q.label = 55;
5341
+ case 55:
5342
+ if (!(_p < fieldData_2.length)) return [3 /*break*/, 58];
5343
+ obj = fieldData_2[_p];
5344
+ return [4 /*yield*/, ValidateUserInput({ 'userInput': obj, 'pageData': pageData, 'objectID': documentID, 'db': db, 'collectionField': fieldName })];
5345
+ case 56:
5346
+ validateResp = _q.sent();
5286
5347
  if (validateResp && validateResp != "") {
5287
5348
  msg = validateResp;
5288
- return [3 /*break*/, 56];
5349
+ return [3 /*break*/, 58];
5289
5350
  }
5290
- _p.label = 55;
5291
- case 55:
5292
- _o++;
5293
- return [3 /*break*/, 53];
5294
- case 56: return [3 /*break*/, 57];
5295
- case 57: return [3 /*break*/, 59];
5296
- case 58:
5351
+ _q.label = 57;
5352
+ case 57:
5353
+ _p++;
5354
+ return [3 /*break*/, 55];
5355
+ case 58: return [3 /*break*/, 59];
5356
+ case 59: return [3 /*break*/, 61];
5357
+ case 60:
5297
5358
  if (!IsSystemField(objectName, fieldName) && !IsAnotherObjectField(pageData, fieldName)) {
5298
5359
  msg = fieldName + " is not valid schema!";
5299
5360
  return [2 /*return*/, "break"];
5300
5361
  }
5301
- _p.label = 59;
5302
- case 59: return [2 /*return*/];
5362
+ _q.label = 61;
5363
+ case 61: return [2 /*return*/];
5303
5364
  }
5304
5365
  });
5305
5366
  };
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
- {
2
- "name": "@optimiser/common",
3
- "version": "1.0.425",
4
- "description": "",
5
- "main": "dist/index.js",
6
- "scripts": {
7
- "compile": "tsc",
8
- "push": "tsc && npm version patch -git-tag-version false && npm publish"
9
- },
10
- "files": [
11
- "dist/*"
12
- ],
13
- "author": "",
14
- "license": "ISC",
15
- "dependencies": {
16
- "@types/geoip-lite": "^1.4.0",
17
- "@types/promise.allsettled": "^1.0.3",
18
- "@types/request": "^2.48.5",
19
- "@types/sanitize-html": "^2.11.0",
20
- "@types/sequelize": "^4.28.9",
21
- "@types/unzipper": "^0.10.3",
22
- "@types/uuid": "^8.3.0",
23
- "aws-sdk": "^2.786.0",
24
- "axios": "^0.21.4",
25
- "bson": "^4.2.0",
26
- "exceljs": "^4.3.0",
27
- "express": "^4.17.1",
28
- "express-validator": "^6.9.2",
29
- "firebase-admin": "^12.0.0",
30
- "geoip-lite": "^1.4.2",
31
- "google-libphonenumber": "^3.2.30",
32
- "ioredis": "^4.17.3",
33
- "libphonenumber-js": "^1.9.51",
34
- "moment": "^2.25.3",
35
- "moment-timezone": "^0.5.27",
36
- "mongo-sanitize": "^1.1.0",
37
- "mongodb": "^3.6.2",
38
- "nodemailer": "^6.4.11",
39
- "promise.allsettled": "^1.0.2",
40
- "qrcode": "^1.5.3",
41
- "request": "^2.88.2",
42
- "sanitize-html": "^2.13.0",
43
- "sequelize": "^6.3.5",
44
- "typescript": "^5.3.3",
45
- "unzipper": "^0.10.11",
46
- "uuid": "^8.3.1"
47
- },
48
- "devDependencies": {
49
- "@types/aws-sdk": "^2.7.0",
50
- "@types/bson": "^4.0.2",
51
- "@types/exceljs": "^1.3.0",
52
- "@types/express": "^4.17.8",
53
- "@types/ioredis": "^4.17.4",
54
- "@types/moment": "^2.13.0",
55
- "@types/moment-timezone": "^0.5.30",
56
- "@types/mongodb": "^3.5.27",
57
- "@types/nodemailer": "^6.4.0"
58
- }
59
- }
1
+ {
2
+ "name": "@optimiser/common",
3
+ "version": "1.0.427",
4
+ "description": "",
5
+ "main": "dist/index.js",
6
+ "scripts": {
7
+ "compile": "tsc",
8
+ "push": "tsc && npm version patch -git-tag-version false && npm publish"
9
+ },
10
+ "files": [
11
+ "dist/*"
12
+ ],
13
+ "author": "",
14
+ "license": "ISC",
15
+ "dependencies": {
16
+ "@types/geoip-lite": "^1.4.0",
17
+ "@types/promise.allsettled": "^1.0.3",
18
+ "@types/request": "^2.48.5",
19
+ "@types/sanitize-html": "^2.11.0",
20
+ "@types/sequelize": "^4.28.9",
21
+ "@types/unzipper": "^0.10.3",
22
+ "@types/uuid": "^8.3.0",
23
+ "aws-sdk": "^2.786.0",
24
+ "axios": "^0.21.4",
25
+ "bson": "^4.2.0",
26
+ "exceljs": "^4.3.0",
27
+ "express": "^4.17.1",
28
+ "express-validator": "^6.9.2",
29
+ "firebase-admin": "^12.0.0",
30
+ "geoip-lite": "^1.4.2",
31
+ "google-libphonenumber": "^3.2.30",
32
+ "ioredis": "^4.17.3",
33
+ "libphonenumber-js": "^1.9.51",
34
+ "moment": "^2.25.3",
35
+ "moment-timezone": "^0.5.27",
36
+ "mongo-sanitize": "^1.1.0",
37
+ "mongodb": "^3.6.2",
38
+ "nodemailer": "^6.4.11",
39
+ "promise.allsettled": "^1.0.2",
40
+ "qrcode": "^1.5.3",
41
+ "request": "^2.88.2",
42
+ "sanitize-html": "^2.13.0",
43
+ "sequelize": "^6.3.5",
44
+ "typescript": "^5.3.3",
45
+ "unzipper": "^0.10.11",
46
+ "uuid": "^8.3.1"
47
+ },
48
+ "devDependencies": {
49
+ "@types/aws-sdk": "^2.7.0",
50
+ "@types/bson": "^4.0.2",
51
+ "@types/exceljs": "^1.3.0",
52
+ "@types/express": "^4.17.8",
53
+ "@types/ioredis": "^4.17.4",
54
+ "@types/moment": "^2.13.0",
55
+ "@types/moment-timezone": "^0.5.30",
56
+ "@types/mongodb": "^3.5.27",
57
+ "@types/nodemailer": "^6.4.0"
58
+ }
59
+ }