@optimiser/common 1.0.294 → 1.0.296

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 +149 -41
  2. package/package.json +1 -1
@@ -1589,6 +1589,16 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1589
1589
  else if (data && data.length > 0) {
1590
1590
  fldLookupData_1 = data[0];
1591
1591
  updateObj[alias_1] = fldLookupData_1;
1592
+ //** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
1593
+ var result = '';
1594
+ if (fieldSchema.LookupFields != undefined) {
1595
+ for (var j = 0; j < fieldSchema.LookupFields.length; j++) {
1596
+ if (fldLookupData_1[fieldSchema.LookupFields[j]] != undefined)
1597
+ result += fldLookupData_1[fieldSchema.LookupFields[j]].toString() + ' ';
1598
+ }
1599
+ }
1600
+ updateObj[searchAlias_1] = result === null || result === void 0 ? void 0 : result.trim();
1601
+ //** Ends here */
1592
1602
  }
1593
1603
  resolve();
1594
1604
  });
@@ -1604,12 +1614,16 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1604
1614
  aggregateArry.push({ $project: { _id: 0, Key: '$Data.Key', Value: '$Data.Value', IsActive: '$Data.IsActive' } });
1605
1615
  aggregateArry.push({ $match: { 'Key': fldValue_1 } });
1606
1616
  db.collection('ListSchema').aggregate(aggregateArry).toArray(function (err, data) {
1617
+ var _a;
1607
1618
  if (err) {
1608
1619
  errorHandler(fldValue_1, err);
1609
1620
  }
1610
1621
  else if (data && data.length > 0) {
1611
1622
  fldLookupData_1 = data[0];
1612
1623
  updateObj[alias_1] = fldLookupData_1;
1624
+ //** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
1625
+ updateObj[searchAlias_1] = (_a = fldLookupData_1.Value) === null || _a === void 0 ? void 0 : _a.trim();
1626
+ //** Ends here */
1613
1627
  }
1614
1628
  resolve();
1615
1629
  });
@@ -1626,6 +1640,19 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1626
1640
  else if (data && data.length > 0) {
1627
1641
  fldLookupData_1 = data;
1628
1642
  updateObj[alias_1] = fldLookupData_1;
1643
+ //** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
1644
+ var result = '';
1645
+ for (var i = 0; i < data.length; i++) {
1646
+ var lookupRecord = data[i];
1647
+ if (fieldSchema.LookupFields != undefined) {
1648
+ for (var j = 0; j < fieldSchema.LookupFields.length; j++) {
1649
+ if (lookupRecord[fieldSchema.LookupFields[j]] != undefined)
1650
+ result += lookupRecord[fieldSchema.LookupFields[j]].toString() + ' ';
1651
+ }
1652
+ }
1653
+ }
1654
+ updateObj[searchAlias_1] = result === null || result === void 0 ? void 0 : result.trim();
1655
+ //** Ends here */
1629
1656
  }
1630
1657
  resolve();
1631
1658
  });
@@ -1636,12 +1663,21 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1636
1663
  aggregateArry.push({ $project: { _id: 0, Key: '$Data.Key', Value: '$Data.Value', IsActive: '$Data.IsActive' } });
1637
1664
  aggregateArry.push({ $match: { 'Key': { $in: fldValue_1 } } });
1638
1665
  db.collection('ListSchema').aggregate(aggregateArry).toArray(function (err, data) {
1666
+ var _a;
1639
1667
  if (err) {
1640
1668
  errorHandler(fldValue_1, err);
1641
1669
  }
1642
1670
  else if (data && data.length > 0) {
1643
1671
  fldLookupData_1 = data;
1644
1672
  updateObj[alias_1] = fldLookupData_1;
1673
+ //** Below code is added by Shahzaib on 05/09/2022 to create SearchValue */
1674
+ var result = '';
1675
+ for (var i = 0; i < data.length; i++) {
1676
+ var lookupRecord = data[i];
1677
+ result += ((_a = lookupRecord.Value) === null || _a === void 0 ? void 0 : _a.toString()) + ' ';
1678
+ }
1679
+ updateObj[searchAlias_1] = result === null || result === void 0 ? void 0 : result.trim();
1680
+ //** Ends here */
1645
1681
  }
1646
1682
  resolve();
1647
1683
  });
@@ -3409,7 +3445,7 @@ function SyncListSchemaFieldInOtherCollection(syncFields, db, msp_d) {
3409
3445
  }
3410
3446
  ]).toArray(function (err, data) {
3411
3447
  return __awaiter(this, void 0, void 0, function () {
3412
- var modifiedObj, _i, data_1, obj, query, schemaData, fieldSchema, alias, i, query;
3448
+ var modifiedObj, _i, data_1, obj, query, schemaData, fieldSchema, alias, i, query, bulkOps;
3413
3449
  var _a, _b, _c, _d, _e, _f;
3414
3450
  return __generator(this, function (_g) {
3415
3451
  switch (_g.label) {
@@ -3422,7 +3458,7 @@ function SyncListSchemaFieldInOtherCollection(syncFields, db, msp_d) {
3422
3458
  _i = 0, data_1 = data;
3423
3459
  _g.label = 1;
3424
3460
  case 1:
3425
- if (!(_i < data_1.length)) return [3 /*break*/, 5];
3461
+ if (!(_i < data_1.length)) return [3 /*break*/, 7];
3426
3462
  obj = data_1[_i];
3427
3463
  query = {
3428
3464
  ObjectName: obj.Name
@@ -3434,60 +3470,66 @@ function SyncListSchemaFieldInOtherCollection(syncFields, db, msp_d) {
3434
3470
  return [4 /*yield*/, BuildLookupDataField(fieldSchema, modifiedObj, db)];
3435
3471
  case 3:
3436
3472
  _g.sent();
3437
- if (obj.Fields.ListSchemaName == syncFields.ListSchemaName || (obj.Fields.IsMultipleListSchemaName && obj.Fields.ListSchemaName.includes(syncFields.ListSchemaName))) {
3438
- alias = obj.Fields.Name + constants_1.default.LookupAlias;
3439
- query.match = (_a = {},
3440
- _a[obj.Fields.Name] = syncFields.ListKey,
3441
- _a);
3442
- if (obj.Fields.UIDataType == 'multiselect') {
3443
- if (syncFields.IsDeleteValue)
3444
- query.set = (_b = {}, _b[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].IsActive'] = false, _b);
3445
- else
3446
- query.set = (_c = {}, _c[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].Value'] = syncFields.Value, _c);
3447
- query.arrayFilters = (_d = {},
3448
- _d['e.Key'] = syncFields.ListKey,
3449
- _d);
3450
- }
3451
- else {
3452
- if (syncFields.IsDeleteValue)
3453
- query.set = (_e = {}, _e[alias + '.IsActive'] = false, _e);
3454
- else
3455
- query.set = (_f = {}, _f[alias + '.Value'] = syncFields.Value, _f);
3456
- }
3457
- query.set = __assign(__assign({}, query.set), modifiedObj);
3473
+ if (!(obj.Fields.ListSchemaName == syncFields.ListSchemaName || (obj.Fields.IsMultipleListSchemaName && obj.Fields.ListSchemaName.includes(syncFields.ListSchemaName)))) return [3 /*break*/, 5];
3474
+ alias = obj.Fields.Name + constants_1.default.LookupAlias;
3475
+ query.match = (_a = {},
3476
+ _a[obj.Fields.Name] = syncFields.ListKey,
3477
+ _a);
3478
+ if (obj.Fields.UIDataType == 'multiselect') {
3479
+ if (syncFields.IsDeleteValue)
3480
+ query.set = (_b = {}, _b[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].IsActive'] = false, _b);
3481
+ else
3482
+ query.set = (_c = {}, _c[obj.Fields.Name + constants_1.default.LookupAlias + '.$[e].Value'] = syncFields.Value, _c);
3483
+ query.arrayFilters = (_d = {},
3484
+ _d['e.Key'] = syncFields.ListKey,
3485
+ _d);
3458
3486
  }
3487
+ else {
3488
+ if (syncFields.IsDeleteValue)
3489
+ query.set = (_e = {}, _e[alias + '.IsActive'] = false, _e);
3490
+ else
3491
+ query.set = (_f = {}, _f[alias + '.Value'] = syncFields.Value, _f);
3492
+ }
3493
+ query.set = __assign(__assign({}, query.set), modifiedObj);
3494
+ if (!!syncFields.IsDeleteValue) return [3 /*break*/, 5];
3495
+ return [4 /*yield*/, BuildSearchValueQuery(syncFields, obj, query, db)];
3496
+ case 4:
3497
+ _g.sent();
3498
+ _g.label = 5;
3499
+ case 5:
3459
3500
  if (query.set && query.match) {
3460
3501
  querys.push(query);
3461
3502
  }
3462
- _g.label = 4;
3463
- case 4:
3503
+ _g.label = 6;
3504
+ case 6:
3464
3505
  _i++;
3465
3506
  return [3 /*break*/, 1];
3466
- case 5:
3507
+ case 7:
3467
3508
  if (!(querys.length > 0)) return [3 /*break*/, 11];
3468
3509
  i = 0;
3469
- _g.label = 6;
3470
- case 6:
3510
+ _g.label = 8;
3511
+ case 8:
3471
3512
  if (!(i < querys.length)) return [3 /*break*/, 11];
3472
3513
  query = querys[i];
3473
- if (!(query.arrayFilters !== undefined)) return [3 /*break*/, 8];
3474
- return [4 /*yield*/, db.collection(query.ObjectName).updateMany(query.match, {
3475
- $set: query.set
3476
- }, {
3477
- arrayFilters: [query.arrayFilters]
3478
- })];
3479
- case 7:
3480
- _g.sent();
3481
- return [3 /*break*/, 10];
3482
- case 8: return [4 /*yield*/, db.collection(query.ObjectName).updateMany(query.match, {
3483
- $set: query.set
3484
- })];
3514
+ bulkOps = [];
3515
+ if (query.arrayFilters !== undefined) {
3516
+ // await db.collection(query.ObjectName).updateMany(query.match, { $set: query.set }, { arrayFilters: [query.arrayFilters] });
3517
+ bulkOps.push({ updateMany: { filter: query.match, update: { $set: query.set }, arrayFilters: [query.arrayFilters] } });
3518
+ }
3519
+ else {
3520
+ // await db.collection(query.ObjectName).updateMany(query.match, { $set: query.set });
3521
+ bulkOps.push({ updateMany: { filter: query.match, update: { $set: query.set } } });
3522
+ }
3523
+ if (query.setSearchValue && query.setSearchValue.length > 0) {
3524
+ bulkOps.push.apply(bulkOps, query.setSearchValue);
3525
+ }
3526
+ return [4 /*yield*/, db.collection(query.ObjectName).bulkWrite(bulkOps)];
3485
3527
  case 9:
3486
3528
  _g.sent();
3487
3529
  _g.label = 10;
3488
3530
  case 10:
3489
3531
  i++;
3490
- return [3 /*break*/, 6];
3532
+ return [3 /*break*/, 8];
3491
3533
  case 11:
3492
3534
  resolve();
3493
3535
  return [2 /*return*/];
@@ -3500,6 +3542,64 @@ function SyncListSchemaFieldInOtherCollection(syncFields, db, msp_d) {
3500
3542
  }); });
3501
3543
  }
3502
3544
  exports.SyncListSchemaFieldInOtherCollection = SyncListSchemaFieldInOtherCollection;
3545
+ //** Build _SearchValue to update in other collections, added by Shahzaib on 18-09-2022 */
3546
+ function BuildSearchValueQuery(syncObject, fieldObj, query, db) {
3547
+ var _a, _b;
3548
+ return __awaiter(this, void 0, void 0, function () {
3549
+ var field, alias, project, syncObjectsData, i, lookupRecord, setQuery, result, j, lookupRecordData, ex_2;
3550
+ var _c;
3551
+ return __generator(this, function (_d) {
3552
+ switch (_d.label) {
3553
+ case 0:
3554
+ _d.trys.push([0, 2, , 3]);
3555
+ field = fieldObj.Fields;
3556
+ alias = field.Name + '_LookupData';
3557
+ project = (_c = {}, _c[field.Name] = 1, _c[alias] = 1, _c);
3558
+ query.setSearchValue = [];
3559
+ return [4 /*yield*/, db.collection(query.ObjectName).find(query.match, { projection: project }).toArray()];
3560
+ case 1:
3561
+ syncObjectsData = _d.sent();
3562
+ if (syncObjectsData && syncObjectsData.length > 0) {
3563
+ for (i = 0; i < syncObjectsData.length; i++) {
3564
+ lookupRecord = syncObjectsData[i][alias];
3565
+ setQuery = {};
3566
+ switch (field.UIDataType) {
3567
+ case "dropdown":
3568
+ setQuery[field.Name + '_SearchValue'] = (_a = syncObject.Value) === null || _a === void 0 ? void 0 : _a.trim();
3569
+ query.setSearchValue.push({ updateOne: { filter: { '_id': syncObjectsData[i]._id }, update: { $set: setQuery } } });
3570
+ break;
3571
+ case "multiselect":
3572
+ {
3573
+ result = '';
3574
+ for (j = 0; j < lookupRecord.length; j++) {
3575
+ lookupRecordData = lookupRecord[j];
3576
+ if (lookupRecordData.Key == syncObject.ListKey) {
3577
+ if (syncObject.Value != undefined)
3578
+ result += syncObject.Value.toString() + ' ';
3579
+ }
3580
+ else {
3581
+ result += ((_b = lookupRecordData.Value) === null || _b === void 0 ? void 0 : _b.toString()) + ' ';
3582
+ }
3583
+ }
3584
+ setQuery[field.Name + '_SearchValue'] = result.trim();
3585
+ query.setSearchValue.push({ updateOne: { filter: { '_id': syncObjectsData[i]._id }, update: { $set: setQuery } } });
3586
+ }
3587
+ break;
3588
+ default:
3589
+ break;
3590
+ }
3591
+ }
3592
+ }
3593
+ return [3 /*break*/, 3];
3594
+ case 2:
3595
+ ex_2 = _d.sent();
3596
+ console.log(ex_2);
3597
+ return [3 /*break*/, 3];
3598
+ case 3: return [2 /*return*/];
3599
+ }
3600
+ });
3601
+ });
3602
+ }
3503
3603
  function UpdateTagCountAfterDelete(objectids, objectName, db, params) {
3504
3604
  return __awaiter(this, void 0, void 0, function () {
3505
3605
  var mongodbQueryOpts;
@@ -4652,6 +4752,10 @@ function ValidateUserInput(options) {
4652
4752
  case 21:
4653
4753
  if (!(field.LookupObject !== undefined)) return [3 /*break*/, 23];
4654
4754
  searchObj = { _id: fieldData };
4755
+ if (field.LookupKey) {
4756
+ searchObj = {};
4757
+ searchObj[field.LookupKey] = fieldData;
4758
+ }
4655
4759
  if (action == 'add') {
4656
4760
  searchObj.IsActive = true;
4657
4761
  }
@@ -4687,6 +4791,10 @@ function ValidateUserInput(options) {
4687
4791
  case 27:
4688
4792
  if (!(field.LookupObject !== undefined)) return [3 /*break*/, 29];
4689
4793
  searchObj = { _id: { $in: fieldData } };
4794
+ if (field.LookupKey) {
4795
+ searchObj = {};
4796
+ searchObj[field.LookupKey] = fieldData;
4797
+ }
4690
4798
  if (action == 'add') {
4691
4799
  searchObj.IsActive = true;
4692
4800
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.294",
3
+ "version": "1.0.296",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {