@optimiser/common 1.0.284 → 1.0.285

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.
@@ -1,6 +1,7 @@
1
1
  declare const _default: {
2
2
  LookupAlias: string;
3
3
  LookupTypeFields: string[];
4
+ SearchValueAlias: string;
4
5
  USER_STATUS: {
5
6
  ACTIVE: string;
6
7
  SUSPEND: string;
package/dist/constants.js CHANGED
@@ -3,6 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  LookupAlias: '_LookupData',
5
5
  LookupTypeFields: ["lookup", "multilookup", "dropdown", "multiselect", "file", "image"],
6
+ SearchValueAlias: '_SearchValue',
6
7
  USER_STATUS: {
7
8
  ACTIVE: 'Active',
8
9
  SUSPEND: 'Suspend',
@@ -28,6 +28,9 @@ declare function SyncFieldInSameCollection(objectName: string, objectIDs: Object
28
28
  declare function SyncFieldInSameCollectionByObjectID(objectName: string, objectID: ObjectId, db: Db): void;
29
29
  declare function SyncFieldInSameCollectionByObjectIDWithPromise(objectName: string, objectID: ObjectId, db: Db): Promise<any>;
30
30
  declare function SyncFieldInOtherCollection(syncFields: AnyObjectInterface[], db: Db): Promise<any>;
31
+ /** Special Note: Need to create seachValue for it in QPC-6169.
32
+ I've not done yet, cause it was not calling from anywhere.
33
+ */
31
34
  declare function SyncUserInOtherCollection(options: AnyObjectInterface, db: Db, callback: callBackInterface, next: NextFunction): void;
32
35
  declare function BuildLookupDataField(fieldSchema: AnyObjectInterface, updateObj: AnyObjectInterface, db: Db): Promise<void>;
33
36
  declare function CheckDataBeforeAdd(updateObj: AnyObjectInterface, objectSchema: AnyObjectInterface, db: Db): Promise<void>;
@@ -1020,7 +1020,7 @@ function SyncFieldInSameCollection(objectName, objectIDs, db) {
1020
1020
  }
1021
1021
  db.collection(objectName).find(findObj).forEach(function (objectData) {
1022
1022
  return __awaiter(this, void 0, void 0, function () {
1023
- var updateObj, i, fieldSchema, lookupData, ex_1;
1023
+ var updateObj, i, fieldSchema, lookupData, searchValue, ex_1;
1024
1024
  return __generator(this, function (_a) {
1025
1025
  switch (_a.label) {
1026
1026
  case 0:
@@ -1038,8 +1038,13 @@ function SyncFieldInSameCollection(objectName, objectIDs, db) {
1038
1038
  case 3:
1039
1039
  _a.sent();
1040
1040
  lookupData = objectData[fieldSchema.Name + constants_1.default.LookupAlias];
1041
- if (lookupData !== undefined)
1041
+ if (lookupData !== undefined) {
1042
1042
  updateObj[fieldSchema.Name + constants_1.default.LookupAlias] = lookupData;
1043
+ }
1044
+ searchValue = objectData[fieldSchema.Name + constants_1.default.SearchValueAlias];
1045
+ if (searchValue !== undefined) {
1046
+ updateObj[fieldSchema.Name + constants_1.default.SearchValueAlias] = searchValue;
1047
+ }
1043
1048
  _a.label = 4;
1044
1049
  case 4:
1045
1050
  i++;
@@ -1095,7 +1100,7 @@ function SyncFieldInSameCollectionByObjectID(objectName, objectID, db) {
1095
1100
  if (fieldArr_2) {
1096
1101
  db.collection(objectName).findOne({ '_id': objectID }, function (err, objectData) {
1097
1102
  return __awaiter(this, void 0, void 0, function () {
1098
- var updateObj, i, fieldSchema, lookupData;
1103
+ var updateObj, i, fieldSchema, lookupData, searchValue;
1099
1104
  return __generator(this, function (_a) {
1100
1105
  switch (_a.label) {
1101
1106
  case 0:
@@ -1110,8 +1115,13 @@ function SyncFieldInSameCollectionByObjectID(objectName, objectID, db) {
1110
1115
  case 2:
1111
1116
  _a.sent();
1112
1117
  lookupData = objectData[fieldSchema.Name + constants_1.default.LookupAlias];
1113
- if (lookupData !== undefined)
1118
+ if (lookupData !== undefined) {
1114
1119
  updateObj[fieldSchema.Name + constants_1.default.LookupAlias] = lookupData;
1120
+ }
1121
+ searchValue = objectData[fieldSchema.Name + constants_1.default.SearchValueAlias];
1122
+ if (searchValue !== undefined) {
1123
+ updateObj[fieldSchema.Name + constants_1.default.SearchValueAlias] = searchValue;
1124
+ }
1115
1125
  _a.label = 3;
1116
1126
  case 3:
1117
1127
  i++;
@@ -1140,7 +1150,7 @@ function SyncFieldInSameCollectionByObjectIDWithPromise(objectName, objectID, db
1140
1150
  if (fieldArr_3) {
1141
1151
  db.collection(objectName).findOne({ '_id': objectID }, function (err, objectData) {
1142
1152
  return __awaiter(this, void 0, void 0, function () {
1143
- var updateObj, i, fieldSchema, lookupData;
1153
+ var updateObj, i, fieldSchema, lookupData, searchValue;
1144
1154
  return __generator(this, function (_a) {
1145
1155
  switch (_a.label) {
1146
1156
  case 0:
@@ -1155,8 +1165,13 @@ function SyncFieldInSameCollectionByObjectIDWithPromise(objectName, objectID, db
1155
1165
  case 2:
1156
1166
  _a.sent();
1157
1167
  lookupData = objectData[fieldSchema.Name + constants_1.default.LookupAlias];
1158
- if (lookupData !== undefined)
1168
+ if (lookupData !== undefined) {
1159
1169
  updateObj[fieldSchema.Name + constants_1.default.LookupAlias] = lookupData;
1170
+ }
1171
+ searchValue = objectData[fieldSchema.Name + constants_1.default.SearchValueAlias];
1172
+ if (searchValue !== undefined) {
1173
+ updateObj[fieldSchema.Name + constants_1.default.SearchValueAlias] = searchValue;
1174
+ }
1160
1175
  _a.label = 3;
1161
1176
  case 3:
1162
1177
  i++;
@@ -1188,6 +1203,7 @@ function SyncFieldInSameCollectionByObjectIDWithPromise(objectName, objectID, db
1188
1203
  });
1189
1204
  }
1190
1205
  exports.SyncFieldInSameCollectionByObjectIDWithPromise = SyncFieldInSameCollectionByObjectIDWithPromise;
1206
+ //** SyncFieldInOtherCollection function is moved in fieldlistener service by Satyam */
1191
1207
  //Sync field in other collection after update
1192
1208
  function SyncFieldInOtherCollection(syncFields, db) {
1193
1209
  var _this = this;
@@ -1306,6 +1322,9 @@ exports.SyncFieldInOtherCollection = SyncFieldInOtherCollection;
1306
1322
  /*Sync user in other collection after replace user
1307
1323
  *this function is used in /replaceuser api
1308
1324
  */
1325
+ /** Special Note: Need to create seachValue for it in QPC-6169.
1326
+ I've not done yet, cause it was not calling from anywhere.
1327
+ */
1309
1328
  function SyncUserInOtherCollection(options, db, callback, next) {
1310
1329
  var userData = options.userData;
1311
1330
  var msp_d = options.msp_d;
@@ -1454,6 +1473,7 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1454
1473
  var fldName = fieldSchema.Name;
1455
1474
  var fldValue_1 = updateObj[fldName];
1456
1475
  var alias_1 = fldName + constants_1.default.LookupAlias;
1476
+ var searchAlias_1 = fldName + constants_1.default.SearchValueAlias;
1457
1477
  var fldLookupData_1 = null;
1458
1478
  if (fldValue_1) {
1459
1479
  var aggregateArry = [];
@@ -1495,6 +1515,22 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1495
1515
  else if (data && data.length > 0) {
1496
1516
  fldLookupData_1 = data[0];
1497
1517
  updateObj[alias_1] = fldLookupData_1;
1518
+ //** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
1519
+ var result = '';
1520
+ if (fieldSchema.LookupFields != undefined) {
1521
+ var _loop_10 = function (j) {
1522
+ if (fieldSchema.ExcludeLookupFieldsOnSearch && fieldSchema.ExcludeLookupFieldsOnSearch.filter(function (x) { return x == fieldSchema.LookupFields[j]; }).length != 0) {
1523
+ return "continue";
1524
+ }
1525
+ if (fldLookupData_1[fieldSchema.LookupFields[j]] != undefined)
1526
+ result += fldLookupData_1[fieldSchema.LookupFields[j]].toString() + ' ';
1527
+ };
1528
+ for (var j = 0; j < fieldSchema.LookupFields.length; j++) {
1529
+ _loop_10(j);
1530
+ }
1531
+ }
1532
+ updateObj[searchAlias_1] = result === null || result === void 0 ? void 0 : result.trim();
1533
+ //** Ends here */
1498
1534
  }
1499
1535
  resolve();
1500
1536
  });
@@ -1524,6 +1560,19 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1524
1560
  else if (data && data.length > 0) {
1525
1561
  fldLookupData_1 = data;
1526
1562
  updateObj[alias_1] = fldLookupData_1;
1563
+ //** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
1564
+ var result = '';
1565
+ for (var i = 0; i < data.length; i++) {
1566
+ var lookupRecord = data[i];
1567
+ if (fieldSchema.LookupFields != undefined) {
1568
+ for (var j = 0; j < fieldSchema.LookupFields.length; j++) {
1569
+ if (lookupRecord[fieldSchema.LookupFields[j]] != undefined)
1570
+ result += lookupRecord[fieldSchema.LookupFields[j]].toString() + ' ';
1571
+ }
1572
+ }
1573
+ }
1574
+ updateObj[searchAlias_1] = result === null || result === void 0 ? void 0 : result.trim();
1575
+ //** Ends here */
1527
1576
  }
1528
1577
  resolve();
1529
1578
  });
@@ -1625,6 +1674,10 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1625
1674
  }
1626
1675
  else {
1627
1676
  updateObj[alias_1] = fldLookupData_1;
1677
+ // Below if cond was added by Shahzaib on 05/09/2022
1678
+ if (fieldSchema.UIDataType == 'lookup' || fieldSchema.UIDataType == 'multilookup') {
1679
+ updateObj[searchAlias_1] = fldLookupData_1;
1680
+ }
1628
1681
  resolve();
1629
1682
  }
1630
1683
  }
@@ -1637,11 +1690,11 @@ exports.BuildLookupDataField = BuildLookupDataField;
1637
1690
  //CheckDataBeforeAdd it sync object before add
1638
1691
  function CheckDataBeforeAdd(updateObj, objectSchema, db) {
1639
1692
  return __awaiter(this, void 0, void 0, function () {
1640
- var _loop_10, _i, _a, fldName;
1693
+ var _loop_11, _i, _a, fldName;
1641
1694
  return __generator(this, function (_b) {
1642
1695
  switch (_b.label) {
1643
1696
  case 0:
1644
- _loop_10 = function (fldName) {
1697
+ _loop_11 = function (fldName) {
1645
1698
  var fieldSchema, sequenceDocument, val, j, item, num;
1646
1699
  return __generator(this, function (_a) {
1647
1700
  switch (_a.label) {
@@ -1687,7 +1740,7 @@ function CheckDataBeforeAdd(updateObj, objectSchema, db) {
1687
1740
  case 1:
1688
1741
  if (!(_i < _a.length)) return [3 /*break*/, 4];
1689
1742
  fldName = _a[_i];
1690
- return [5 /*yield**/, _loop_10(fldName)];
1743
+ return [5 /*yield**/, _loop_11(fldName)];
1691
1744
  case 2:
1692
1745
  _b.sent();
1693
1746
  _b.label = 3;
@@ -1703,11 +1756,11 @@ exports.CheckDataBeforeAdd = CheckDataBeforeAdd;
1703
1756
  //CheckDataBeforeAdd it sync object before update
1704
1757
  function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1705
1758
  return __awaiter(this, void 0, void 0, function () {
1706
- var _loop_11, _i, _a, fldName;
1759
+ var _loop_12, _i, _a, fldName;
1707
1760
  return __generator(this, function (_b) {
1708
1761
  switch (_b.label) {
1709
1762
  case 0:
1710
- _loop_11 = function (fldName) {
1763
+ _loop_12 = function (fldName) {
1711
1764
  var fieldSchema, oldValue, newValue, isSame;
1712
1765
  return __generator(this, function (_a) {
1713
1766
  switch (_a.label) {
@@ -1750,7 +1803,7 @@ function CheckDataBeforeUpdate(updateObj, objectData, objectSchema, db) {
1750
1803
  case 1:
1751
1804
  if (!(_i < _a.length)) return [3 /*break*/, 4];
1752
1805
  fldName = _a[_i];
1753
- return [5 /*yield**/, _loop_11(fldName)];
1806
+ return [5 /*yield**/, _loop_12(fldName)];
1754
1807
  case 2:
1755
1808
  _b.sent();
1756
1809
  _b.label = 3;
@@ -1769,50 +1822,55 @@ function BuildGridFieldProjection(project, field, group) {
1769
1822
  if (group && group.IsRealLookup)
1770
1823
  fldName = group.Name + '.' + fldName;
1771
1824
  var alias;
1825
+ var searchAlias = fldName + constants_1.default.SearchValueAlias;
1772
1826
  var searchConcatArry = [];
1773
1827
  switch (field.Schema.UIDataType) {
1828
+ // below code was added by Shahzaib on 05/09/2022
1774
1829
  case "lookup":
1775
- alias = fldName + constants_1.default.LookupAlias;
1776
- project[fldName] = 1;
1777
- project[alias] = 1;
1778
- var _loop_12 = function (i) {
1779
- if (field.Schema.ExcludeLookupFieldsOnSearch && field.Schema.ExcludeLookupFieldsOnSearch.filter(function (x) { return x == field.Schema.LookupFields[i]; }).length != 0) {
1780
- return "continue";
1781
- }
1782
- // searchConcatArry.push({ "$ifNull": ['$' + alias + '.' + field.Schema.LookupFields[i], ""] });
1783
- // added by Shahzaib, make int to string and concat
1784
- searchConcatArry.push({ "$ifNull": [{ $toString: '$' + alias + '.' + field.Schema.LookupFields[i] }, ""] });
1785
- if (i < field.Schema.LookupFields.length - 1) {
1786
- searchConcatArry.push(" ");
1787
- }
1788
- };
1789
- for (var i = 0; i < field.Schema.LookupFields.length; i++) {
1790
- _loop_12(i);
1791
- }
1792
- ;
1793
- project[fldName + '_SearchValue'] = { $concat: searchConcatArry };
1794
- break;
1795
1830
  case "multilookup":
1796
1831
  alias = fldName + constants_1.default.LookupAlias;
1797
1832
  project[fldName] = 1;
1798
1833
  project[alias] = 1;
1799
- for (var i = 0; i < field.Schema.LookupFields.length; i++) {
1800
- searchConcatArry.push({ "$ifNull": ['$' + alias + '.' + field.Schema.LookupFields[i], [" "]] });
1801
- if (i < field.Schema.LookupFields.length - 1) {
1802
- searchConcatArry.push([" "]);
1803
- }
1804
- }
1805
- ;
1806
- //project[fldName + '_SearchValue'] = { $concatArrays: searchConcatArry };
1807
- project[fldName + '_SearchValue'] = {
1808
- $reduce: {
1809
- input: { $concatArrays: searchConcatArry },
1810
- initialValue: "",
1811
- //in: { $concat: ["$$value", "$$this"] } // Commented by and below line was added by Shahzaib, make int to string
1812
- in: { $concat: ["$$value", { $toString: "$$this" }] }
1813
- }
1814
- };
1834
+ project[searchAlias] = 1;
1815
1835
  break;
1836
+ // Below code was commented by Shahzaib on 05/09/2022, searchAlias was added instead of it.
1837
+ // case "lookup":
1838
+ // alias = fldName + constants.LookupAlias;
1839
+ // project[fldName] = 1;
1840
+ // project[alias] = 1;
1841
+ // for (let i = 0; i < field.Schema.LookupFields.length; i++) {
1842
+ // if (field.Schema.ExcludeLookupFieldsOnSearch && field.Schema.ExcludeLookupFieldsOnSearch.filter((x: AnyObjectInterface) => x == field.Schema.LookupFields[i]).length != 0) {
1843
+ // continue;
1844
+ // }
1845
+ // // searchConcatArry.push({ "$ifNull": ['$' + alias + '.' + field.Schema.LookupFields[i], ""] });
1846
+ // // added by Shahzaib, make int to string and concat
1847
+ // searchConcatArry.push({ "$ifNull": [{$toString : '$' + alias + '.' + field.Schema.LookupFields[i]}, ""] });
1848
+ // if (i < field.Schema.LookupFields.length - 1) {
1849
+ // searchConcatArry.push(" ");
1850
+ // }
1851
+ // };
1852
+ // project[fldName + '_SearchValue'] = { $concat: searchConcatArry };
1853
+ // break;
1854
+ // case "multilookup":
1855
+ // alias = fldName + constants.LookupAlias;
1856
+ // project[fldName] = 1;
1857
+ // project[alias] = 1;
1858
+ // for (let i = 0; i < field.Schema.LookupFields.length; i++) {
1859
+ // searchConcatArry.push({ "$ifNull": ['$' + alias + '.' + field.Schema.LookupFields[i], [" "]] });
1860
+ // if (i < field.Schema.LookupFields.length - 1) {
1861
+ // searchConcatArry.push([" "]);
1862
+ // }
1863
+ // };
1864
+ // //project[fldName + '_SearchValue'] = { $concatArrays: searchConcatArry };
1865
+ // project[fldName + '_SearchValue'] = {
1866
+ // $reduce: {
1867
+ // input: { $concatArrays: searchConcatArry },
1868
+ // initialValue: "",
1869
+ // //in: { $concat: ["$$value", "$$this"] } // Commented by and below line was added by Shahzaib, make int to string
1870
+ // in: { $concat: ["$$value", { $toString : "$$this" }] }
1871
+ // }
1872
+ // };
1873
+ // break;
1816
1874
  case "dropdown":
1817
1875
  alias = fldName + constants_1.default.LookupAlias;
1818
1876
  project[fldName] = 1;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.284",
3
+ "version": "1.0.285",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {