@optimiser/common 1.0.426 → 1.0.428

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/dist/constants.js CHANGED
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  LookupAlias: '_LookupData',
5
- LookupTypeFields: ["lookup", "multilookup", "dropdown", "multiselect", "file", "image"],
5
+ LookupTypeFields: ["lookup", "multilookup", "dropdown", "multiselect", "file", "image", "video"],
6
6
  SearchValueAlias: '_SearchValue',
7
7
  USER_STATUS: {
8
8
  ACTIVE: 'Active',
@@ -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
  });
@@ -4868,9 +4906,9 @@ function ValidateUserInput(options) {
4868
4906
  }
4869
4907
  }
4870
4908
  _loop_20 = function (pageField) {
4871
- 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;
4872
- return __generator(this, function (_p) {
4873
- 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) {
4874
4912
  case 0:
4875
4913
  if (msg != "") {
4876
4914
  return [2 /*return*/, "break"];
@@ -4881,7 +4919,7 @@ function ValidateUserInput(options) {
4881
4919
  delete inputFields[pageField.Name];
4882
4920
  }
4883
4921
  field = schemaFields.find(function (x) { return x.Name == fieldName; });
4884
- if (!field) return [3 /*break*/, 58];
4922
+ if (!field) return [3 /*break*/, 60];
4885
4923
  //sanitizing Html and added IgnoreSanitizeHtml condition so that it can be ignored for certain fields
4886
4924
  if (!field.IgnoreSanitizeHtml && IsStringValue(fieldData)) {
4887
4925
  inputFields[fieldName] = CustomSanitizeHtml(fieldData, field.UIDataType);
@@ -4916,7 +4954,7 @@ function ValidateUserInput(options) {
4916
4954
  if (!(action === 'update' && (['edit', 'both'].includes(field.DisableON) || ['edit', 'both'].includes(field.HideON)))) return [3 /*break*/, 3];
4917
4955
  return [4 /*yield*/, db.collection(objectName).findOne({ '_id': documentID })];
4918
4956
  case 2:
4919
- parentData = _p.sent();
4957
+ parentData = _q.sent();
4920
4958
  oldValue = parentData[fieldName] != undefined ? parentData[fieldName] : null;
4921
4959
  newValue = fieldData;
4922
4960
  // Check if newValue is undefined
@@ -4934,7 +4972,7 @@ function ValidateUserInput(options) {
4934
4972
  msg = "The field " + field.DisplayName + " was passed in the API request but is not allowed.";
4935
4973
  return [2 /*return*/, "break"];
4936
4974
  }
4937
- _p.label = 3;
4975
+ _q.label = 3;
4938
4976
  case 3:
4939
4977
  if (!(field.IsUnique == true)) return [3 /*break*/, 5];
4940
4978
  if (!(field.UIDataType == "email" && fieldData)) return [3 /*break*/, 5];
@@ -4945,12 +4983,12 @@ function ValidateUserInput(options) {
4945
4983
  }
4946
4984
  return [4 /*yield*/, db.collection(objectSchema.Name).findOne(searchQuery)];
4947
4985
  case 4:
4948
- result = _p.sent();
4986
+ result = _q.sent();
4949
4987
  if (result != null) {
4950
4988
  msg = 'Email already exists for ' + field.DisplayName + '!';
4951
4989
  return [2 /*return*/, "break"];
4952
4990
  }
4953
- _p.label = 5;
4991
+ _q.label = 5;
4954
4992
  case 5:
4955
4993
  // Added by Shahzaib to check conditional field criteria
4956
4994
  if (field.IsConditionalField) {
@@ -4960,8 +4998,8 @@ function ValidateUserInput(options) {
4960
4998
  if (msg != "")
4961
4999
  return [2 /*return*/, "break"];
4962
5000
  }
4963
- if (!inputField.includes(fieldName)) return [3 /*break*/, 57];
4964
- 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];
4965
5003
  _k = field.UIDataType;
4966
5004
  switch (_k) {
4967
5005
  case 'int': return [3 /*break*/, 6];
@@ -4979,12 +5017,13 @@ function ValidateUserInput(options) {
4979
5017
  case 'phone': return [3 /*break*/, 41];
4980
5018
  case "image": return [3 /*break*/, 42];
4981
5019
  case 'file': return [3 /*break*/, 42];
4982
- case 'textarea': return [3 /*break*/, 51];
4983
- case 'text': return [3 /*break*/, 51];
4984
- case 'texteditor': return [3 /*break*/, 51];
4985
- 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];
4986
5025
  }
4987
- return [3 /*break*/, 57];
5026
+ return [3 /*break*/, 59];
4988
5027
  case 6:
4989
5028
  {
4990
5029
  if (IsStringValue(fieldData) || Number.isInteger(fieldData) == false) {
@@ -4997,7 +5036,7 @@ function ValidateUserInput(options) {
4997
5036
  msg = field.DisplayName + ' value must be smaller then or equal to ' + field.MaxValue;
4998
5037
  }
4999
5038
  }
5000
- return [3 /*break*/, 57];
5039
+ return [3 /*break*/, 59];
5001
5040
  case 7:
5002
5041
  {
5003
5042
  minValue = field.MinValue, maxValue = field.MaxValue;
@@ -5015,14 +5054,14 @@ function ValidateUserInput(options) {
5015
5054
  msg = field.DisplayName + ' value must be smaller then or equal to ' + maxValue;
5016
5055
  }
5017
5056
  }
5018
- return [3 /*break*/, 57];
5057
+ return [3 /*break*/, 59];
5019
5058
  case 8:
5020
5059
  {
5021
5060
  if ((fieldData instanceof Date && !isNaN(inputFields[fieldName])) == false) {
5022
5061
  msg = 'Invalid date for ' + field.DisplayName + '!';
5023
5062
  }
5024
5063
  }
5025
- return [3 /*break*/, 57];
5064
+ return [3 /*break*/, 59];
5026
5065
  case 9:
5027
5066
  {
5028
5067
  if (field.ShowNextDayHoursUpto) {
@@ -5040,7 +5079,7 @@ function ValidateUserInput(options) {
5040
5079
  }
5041
5080
  }
5042
5081
  }
5043
- return [3 /*break*/, 57];
5082
+ return [3 /*break*/, 59];
5044
5083
  case 10:
5045
5084
  {
5046
5085
  filter = /^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@(([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,})$/;
@@ -5048,14 +5087,14 @@ function ValidateUserInput(options) {
5048
5087
  msg = fieldData + ' is invalid email for ' + field.DisplayName + '!';
5049
5088
  }
5050
5089
  }
5051
- return [3 /*break*/, 57];
5090
+ return [3 /*break*/, 59];
5052
5091
  case 11:
5053
5092
  {
5054
5093
  if (fieldData !== true && fieldData !== false) {
5055
5094
  msg = 'Invalid user input for ' + field.DisplayName + '!';
5056
5095
  }
5057
5096
  }
5058
- return [3 /*break*/, 57];
5097
+ return [3 /*break*/, 59];
5059
5098
  case 12:
5060
5099
  if (!!field.IsMultipleLookupObject) return [3 /*break*/, 14];
5061
5100
  searchObj = { _id: fieldData };
@@ -5070,12 +5109,12 @@ function ValidateUserInput(options) {
5070
5109
  dbConnection = (field.UseMasterDatabase && mdb) ? mdb : db;
5071
5110
  return [4 /*yield*/, dbConnection.collection(field.LookupObject).findOne(searchObj)];
5072
5111
  case 13:
5073
- result = _p.sent();
5112
+ result = _q.sent();
5074
5113
  if (result == null) {
5075
5114
  msg = field.DisplayName + ' does not exist!';
5076
5115
  }
5077
- _p.label = 14;
5078
- case 14: return [3 /*break*/, 57];
5116
+ _q.label = 14;
5117
+ case 14: return [3 /*break*/, 59];
5079
5118
  case 15:
5080
5119
  if (!Array.isArray(fieldData)) return [3 /*break*/, 22];
5081
5120
  if (!fieldData.length) return [3 /*break*/, 20];
@@ -5091,42 +5130,42 @@ function ValidateUserInput(options) {
5091
5130
  ;
5092
5131
  return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
5093
5132
  case 16:
5094
- totalRecord = _p.sent();
5133
+ totalRecord = _q.sent();
5095
5134
  if (!(objectName == "Activity" && field.Name == 'Attendees')) return [3 /*break*/, 18];
5096
5135
  _l = totalRecord;
5097
5136
  return [4 /*yield*/, db.collection('Contact').find(searchObj).count()];
5098
5137
  case 17:
5099
- totalRecord = _l + _p.sent();
5100
- _p.label = 18;
5138
+ totalRecord = _l + _q.sent();
5139
+ _q.label = 18;
5101
5140
  case 18:
5102
5141
  if (totalRecord !== fieldData.length) {
5103
5142
  msg = field.DisplayName + ' does not exist!';
5104
5143
  }
5105
- _p.label = 19;
5144
+ _q.label = 19;
5106
5145
  case 19: return [3 /*break*/, 21];
5107
5146
  case 20:
5108
5147
  if (field.IsRequired) {
5109
5148
  msg = field.DisplayName + ' is required!';
5110
5149
  }
5111
- _p.label = 21;
5150
+ _q.label = 21;
5112
5151
  case 21: return [3 /*break*/, 23];
5113
5152
  case 22:
5114
5153
  msg = 'Invalid value for ' + field.DisplayName;
5115
- _p.label = 23;
5116
- case 23: return [3 /*break*/, 57];
5154
+ _q.label = 23;
5155
+ case 23: return [3 /*break*/, 59];
5117
5156
  case 24:
5118
5157
  if (!(field.ListSchemaName !== undefined)) return [3 /*break*/, 27];
5119
5158
  if (!!field.IsMultipleListSchemaName) return [3 /*break*/, 26];
5120
5159
  schemaData = null;
5121
5160
  return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
5122
5161
  case 25:
5123
- result = _p.sent();
5162
+ result = _q.sent();
5124
5163
  if (result && result.Data)
5125
5164
  schemaData = result.Data.find(function (x) { return x.Key == fieldData; });
5126
5165
  if (schemaData == null || (action == 'add' && schemaData.IsActive == false)) {
5127
5166
  msg = field.DisplayName + ' does not exist!';
5128
5167
  }
5129
- _p.label = 26;
5168
+ _q.label = 26;
5130
5169
  case 26: return [3 /*break*/, 29];
5131
5170
  case 27:
5132
5171
  if (!(field.LookupObject !== undefined && !field.IsMultipleLookupObject)) return [3 /*break*/, 29];
@@ -5141,12 +5180,12 @@ function ValidateUserInput(options) {
5141
5180
  ;
5142
5181
  return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
5143
5182
  case 28:
5144
- result = _p.sent();
5183
+ result = _q.sent();
5145
5184
  if (result == null) {
5146
5185
  msg = field.DisplayName + ' does not exist!';
5147
5186
  }
5148
- _p.label = 29;
5149
- case 29: return [3 /*break*/, 57];
5187
+ _q.label = 29;
5188
+ case 29: return [3 /*break*/, 59];
5150
5189
  case 30:
5151
5190
  if (!Array.isArray(fieldData)) return [3 /*break*/, 38];
5152
5191
  if (!fieldData.length) return [3 /*break*/, 36];
@@ -5155,7 +5194,7 @@ function ValidateUserInput(options) {
5155
5194
  schemaData = [];
5156
5195
  return [4 /*yield*/, db.collection('ListSchema').findOne({ Name: field.ListSchemaName })];
5157
5196
  case 31:
5158
- result = _p.sent();
5197
+ result = _q.sent();
5159
5198
  if (result && result.Data) {
5160
5199
  if (action == 'add')
5161
5200
  schemaData = result.Data.filter(function (x) { return x.IsActive == true && fieldData.includes(x.Key.toString()); });
@@ -5165,7 +5204,7 @@ function ValidateUserInput(options) {
5165
5204
  if (schemaData.length != fieldData.length) {
5166
5205
  msg = field.DisplayName + ' does not exist!';
5167
5206
  }
5168
- _p.label = 32;
5207
+ _q.label = 32;
5169
5208
  case 32: return [3 /*break*/, 35];
5170
5209
  case 33:
5171
5210
  if (!(field.LookupObject !== undefined && !field.IsMultipleLookupObject)) return [3 /*break*/, 35];
@@ -5180,22 +5219,22 @@ function ValidateUserInput(options) {
5180
5219
  ;
5181
5220
  return [4 /*yield*/, db.collection(field.LookupObject).find(searchObj).count()];
5182
5221
  case 34:
5183
- totalRecord = _p.sent();
5222
+ totalRecord = _q.sent();
5184
5223
  if (totalRecord !== fieldData.length) {
5185
5224
  msg = field.DisplayName + ' does not exist!';
5186
5225
  }
5187
- _p.label = 35;
5226
+ _q.label = 35;
5188
5227
  case 35: return [3 /*break*/, 37];
5189
5228
  case 36:
5190
5229
  if (field.IsRequired) {
5191
5230
  msg = field.DisplayName + ' is required!';
5192
5231
  }
5193
- _p.label = 37;
5232
+ _q.label = 37;
5194
5233
  case 37: return [3 /*break*/, 39];
5195
5234
  case 38:
5196
5235
  msg = 'Invalid value for ' + field.DisplayName;
5197
- _p.label = 39;
5198
- case 39: return [3 /*break*/, 57];
5236
+ _q.label = 39;
5237
+ case 39: return [3 /*break*/, 59];
5199
5238
  case 40:
5200
5239
  {
5201
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');
@@ -5203,7 +5242,7 @@ function ValidateUserInput(options) {
5203
5242
  msg = 'Invalid URL for ' + field.DisplayName + '!';
5204
5243
  }
5205
5244
  }
5206
- return [3 /*break*/, 57];
5245
+ return [3 /*break*/, 59];
5207
5246
  case 41:
5208
5247
  {
5209
5248
  if (field.IncludeCountryCode) {
@@ -5218,7 +5257,7 @@ function ValidateUserInput(options) {
5218
5257
  }
5219
5258
  }
5220
5259
  }
5221
- return [3 /*break*/, 57];
5260
+ return [3 /*break*/, 59];
5222
5261
  case 42:
5223
5262
  if (!field.IsMultiple) return [3 /*break*/, 48];
5224
5263
  if (!Array.isArray(fieldData)) return [3 /*break*/, 46];
@@ -5235,7 +5274,7 @@ function ValidateUserInput(options) {
5235
5274
  ;
5236
5275
  return [4 /*yield*/, db.collection("Drive").find(searchObj).count()];
5237
5276
  case 43:
5238
- totalRecord = _p.sent();
5277
+ totalRecord = _q.sent();
5239
5278
  if (totalRecord !== fieldData.length) {
5240
5279
  msg = field.DisplayName + ' does not exist!';
5241
5280
  }
@@ -5244,11 +5283,11 @@ function ValidateUserInput(options) {
5244
5283
  if (field.IsRequired) {
5245
5284
  msg = field.DisplayName + ' is required!';
5246
5285
  }
5247
- _p.label = 45;
5286
+ _q.label = 45;
5248
5287
  case 45: return [3 /*break*/, 47];
5249
5288
  case 46:
5250
5289
  msg = 'Invalid value for ' + field.DisplayName;
5251
- _p.label = 47;
5290
+ _q.label = 47;
5252
5291
  case 47: return [3 /*break*/, 50];
5253
5292
  case 48:
5254
5293
  searchObj = { _id: fieldData };
@@ -5258,13 +5297,33 @@ function ValidateUserInput(options) {
5258
5297
  ;
5259
5298
  return [4 /*yield*/, db.collection("Drive").findOne(searchObj)];
5260
5299
  case 49:
5261
- result = _p.sent();
5300
+ result = _q.sent();
5262
5301
  if (result == null) {
5263
5302
  msg = field.DisplayName + ' does not exist!';
5264
5303
  }
5265
- _p.label = 50;
5266
- case 50: return [3 /*break*/, 57];
5304
+ _q.label = 50;
5305
+ case 50: return [3 /*break*/, 59];
5267
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:
5268
5327
  {
5269
5328
  // Maxlength check;
5270
5329
  if (field.MaxLength !== undefined && field.MaxLength !== null && fieldData.length > field.MaxLength) {
@@ -5274,34 +5333,34 @@ function ValidateUserInput(options) {
5274
5333
  msg = 'Invalid value for ' + field.DisplayName;
5275
5334
  }
5276
5335
  }
5277
- return [3 /*break*/, 57];
5278
- case 52:
5279
- if (!fieldData.length) return [3 /*break*/, 56];
5280
- _o = 0, fieldData_2 = fieldData;
5281
- _p.label = 53;
5282
- case 53:
5283
- if (!(_o < fieldData_2.length)) return [3 /*break*/, 56];
5284
- obj = fieldData_2[_o];
5285
- return [4 /*yield*/, ValidateUserInput({ 'userInput': obj, 'pageData': pageData, 'objectID': documentID, 'db': db, 'collectionField': fieldName })];
5336
+ return [3 /*break*/, 59];
5286
5337
  case 54:
5287
- 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();
5288
5347
  if (validateResp && validateResp != "") {
5289
5348
  msg = validateResp;
5290
- return [3 /*break*/, 56];
5349
+ return [3 /*break*/, 58];
5291
5350
  }
5292
- _p.label = 55;
5293
- case 55:
5294
- _o++;
5295
- return [3 /*break*/, 53];
5296
- case 56: return [3 /*break*/, 57];
5297
- case 57: return [3 /*break*/, 59];
5298
- 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:
5299
5358
  if (!IsSystemField(objectName, fieldName) && !IsAnotherObjectField(pageData, fieldName)) {
5300
5359
  msg = fieldName + " is not valid schema!";
5301
5360
  return [2 /*return*/, "break"];
5302
5361
  }
5303
- _p.label = 59;
5304
- case 59: return [2 /*return*/];
5362
+ _q.label = 61;
5363
+ case 61: return [2 /*return*/];
5305
5364
  }
5306
5365
  });
5307
5366
  };
package/package.json CHANGED
@@ -1,59 +1,59 @@
1
- {
2
- "name": "@optimiser/common",
3
- "version": "1.0.426",
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.428",
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
+ }