@optimiser/common 1.0.333 → 1.0.335

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 +158 -125
  2. package/package.json +1 -1
@@ -3771,73 +3771,107 @@ function UpdateTagCount(tagids, objectName, db, params) {
3771
3771
  }
3772
3772
  function SyncUserLicenceConsumedCount(msp_d, db, dbMaster) {
3773
3773
  return __awaiter(this, void 0, void 0, function () {
3774
- var companySetting, companyLicencesData_1, i, companyLicenceType, j, err_1;
3774
+ var companySetting, companyLicencesData, i, companyLicenceType, j, userLicenceData, u, licenceType, licenceName, licenceTotal, i, companyLicenceType, j, comLicenceInUserLicence, bulkLicenceOps, u, licenceID, licenceTotal, err_1;
3775
3775
  return __generator(this, function (_a) {
3776
3776
  switch (_a.label) {
3777
3777
  case 0:
3778
- _a.trys.push([0, 2, , 3]);
3778
+ _a.trys.push([0, 8, , 9]);
3779
3779
  return [4 /*yield*/, dbMaster.collection("Company").findOne({ _id: new mongodb_1.ObjectId(msp_d.ci), 'IsActive': true }, { projection: { "Setting.Licences": 1 } })];
3780
3780
  case 1:
3781
3781
  companySetting = _a.sent();
3782
- if (companySetting && companySetting.Setting) {
3783
- companyLicencesData_1 = (companySetting.Setting.Licences) ? companySetting.Setting.Licences : {};
3784
- if (isEmptyObj(companyLicencesData_1) == false) {
3785
- for (i in companyLicencesData_1) {
3786
- /*Added by Chetan on 07-Mar-2022, Not necessary for Domain Licence*/
3787
- if (i != "Domain") {
3788
- companyLicenceType = companyLicencesData_1[i];
3782
+ if (!(companySetting && companySetting.Setting)) return [3 /*break*/, 6];
3783
+ companyLicencesData = (companySetting.Setting.Licences) ? companySetting.Setting.Licences : {};
3784
+ if (!(isEmptyObj(companyLicencesData) == false)) return [3 /*break*/, 4];
3785
+ for (i in companyLicencesData) {
3786
+ /*Added by Chetan on 07-Mar-2022, Not necessary for Domain Licence*/
3787
+ if (i != "Domain") {
3788
+ companyLicenceType = companyLicencesData[i];
3789
+ for (j in companyLicenceType) {
3790
+ companyLicenceType[j].NoOfLicenceConsumed = 0;
3791
+ }
3792
+ }
3793
+ }
3794
+ return [4 /*yield*/, db.collection('UserLicence').aggregate([
3795
+ { $match: { Status: 'active', IsActive: true } },
3796
+ { $group: { _id: { "LicenceType": "$LicenceType", "LicenceName": "$LicenceName" }, Total: { $sum: 1 } } }
3797
+ ]).toArray()];
3798
+ case 2:
3799
+ userLicenceData = _a.sent();
3800
+ if (userLicenceData) {
3801
+ for (u = 0; u < userLicenceData.length; u++) {
3802
+ licenceType = userLicenceData[u]._id['LicenceType'];
3803
+ licenceName = userLicenceData[u]._id['LicenceName'];
3804
+ licenceTotal = userLicenceData[u].Total;
3805
+ for (i in companyLicencesData) {
3806
+ if (i == licenceType) {
3807
+ companyLicenceType = companyLicencesData[i];
3789
3808
  for (j in companyLicenceType) {
3790
- companyLicenceType[j].NoOfLicenceConsumed = 0;
3809
+ if (j == licenceName) {
3810
+ companyLicenceType[j].NoOfLicenceConsumed = licenceTotal;
3811
+ }
3791
3812
  }
3792
3813
  }
3793
3814
  }
3794
- db.collection('UserLicence').aggregate([
3795
- { $match: { Status: 'active', IsActive: true } },
3796
- { $group: { _id: { "LicenceType": "$LicenceType", "LicenceName": "$LicenceName" }, Total: { $sum: 1 } } }
3797
- ]).toArray(function (errUserAggregate, userLicenceData) {
3798
- if (errUserAggregate) {
3799
- console.log(errUserAggregate, 'In company (' + msp_d.ci + '), Error occurred while syncing user licence consumed count.');
3815
+ }
3816
+ dbMaster.collection('Company').updateOne({ _id: new mongodb_1.ObjectId(msp_d.ci), 'IsActive': true }, {
3817
+ $set: {
3818
+ "Setting.Licences": companyLicencesData
3819
+ }
3820
+ });
3821
+ }
3822
+ else {
3823
+ console.log('In company (' + msp_d.ci + '), User Licence data not found while syncing user licence consumed count.');
3824
+ }
3825
+ return [4 /*yield*/, db.collection('UserLicence').aggregate([
3826
+ { $match: { Status: 'active', IsActive: true } },
3827
+ { $group: { _id: { "CompanyLicenceID": "$CompanyLicenceID" }, Total: { $sum: 1 } } }
3828
+ ]).toArray()];
3829
+ case 3:
3830
+ comLicenceInUserLicence = _a.sent();
3831
+ if (comLicenceInUserLicence && comLicenceInUserLicence.length) {
3832
+ bulkLicenceOps = [{
3833
+ updateMany: {
3834
+ filter: { 'CompanyID': new mongodb_1.ObjectId(msp_d.ci), 'LicenceType': { $ne: 'Domain' }, Status: 'active', IsActive: true },
3835
+ update: [
3836
+ { $set: { 'NoOfLicenceConsumed': 0 } },
3837
+ { $set: { 'NoOfRemainingLicence': "$NoOfLicence" } }
3838
+ ]
3800
3839
  }
3801
- else if (userLicenceData) {
3802
- for (var u = 0; u < userLicenceData.length; u++) {
3803
- var licenceType = userLicenceData[u]._id['LicenceType'];
3804
- var licenceName = userLicenceData[u]._id['LicenceName'];
3805
- var licenceTotal = userLicenceData[u].Total;
3806
- for (var i in companyLicencesData_1) {
3807
- if (i == licenceType) {
3808
- var companyLicenceType = companyLicencesData_1[i];
3809
- for (var j in companyLicenceType) {
3810
- if (j == licenceName) {
3811
- companyLicenceType[j].NoOfLicenceConsumed = licenceTotal;
3812
- }
3813
- }
3814
- }
3815
- }
3840
+ }];
3841
+ for (u = 0; u < comLicenceInUserLicence.length; u++) {
3842
+ licenceID = comLicenceInUserLicence[u]._id['CompanyLicenceID'];
3843
+ licenceTotal = comLicenceInUserLicence[u].Total;
3844
+ if (licenceID) {
3845
+ bulkLicenceOps.push({
3846
+ updateOne: {
3847
+ filter: { '_id': licenceID },
3848
+ update: [
3849
+ { $set: { 'NoOfLicenceConsumed': licenceTotal } },
3850
+ { $set: { 'NoOfRemainingLicence': { $subtract: ["$NoOfLicence", "$NoOfLicenceConsumed"] } } }
3851
+ ]
3816
3852
  }
3817
- dbMaster.collection('Company').updateOne({ _id: new mongodb_1.ObjectId(msp_d.ci), 'IsActive': true }, {
3818
- $set: {
3819
- "Setting.Licences": companyLicencesData_1
3820
- }
3821
- });
3822
- }
3823
- else {
3824
- console.log('In company (' + msp_d.ci + '), User Licence data not found while syncing user licence consumed count.');
3825
- }
3826
- });
3827
- }
3828
- else {
3829
- console.log('Licence data not found in company (' + msp_d.ci + ') setting while syncing user licence consumed count.');
3853
+ });
3854
+ }
3830
3855
  }
3856
+ dbMaster.collection('CompanyLicence').bulkWrite(bulkLicenceOps);
3831
3857
  }
3832
3858
  else {
3833
- console.log('Company (' + msp_d.ci + ') data not found while syncing user licence consumed count.');
3859
+ console.log('In company (' + msp_d.ci + '), copmany licence data not found in user licence while syncing user licence consumed count.');
3834
3860
  }
3835
- return [3 /*break*/, 3];
3836
- case 2:
3861
+ return [3 /*break*/, 5];
3862
+ case 4:
3863
+ console.log('Licence data not found in company (' + msp_d.ci + ') setting while syncing user licence consumed count.');
3864
+ _a.label = 5;
3865
+ case 5: return [3 /*break*/, 7];
3866
+ case 6:
3867
+ console.log('Company (' + msp_d.ci + ') data not found while syncing user licence consumed count.');
3868
+ _a.label = 7;
3869
+ case 7: return [3 /*break*/, 9];
3870
+ case 8:
3837
3871
  err_1 = _a.sent();
3838
- console.log(err_1, 'Error occurred while syncing user licence consumed count.');
3839
- return [3 /*break*/, 3];
3840
- case 3: return [2 /*return*/];
3872
+ console.log('Error occurred while syncing user licence consumed count.', err_1);
3873
+ return [3 /*break*/, 9];
3874
+ case 9: return [2 /*return*/];
3841
3875
  }
3842
3876
  });
3843
3877
  });
@@ -3942,95 +3976,92 @@ exports.CheckDataPermission = CheckDataPermission;
3942
3976
  */
3943
3977
  function SyncCompanyLicenceInMasterCompanyAfterAdd(fieldsObj, dbMaster) {
3944
3978
  return __awaiter(this, void 0, void 0, function () {
3945
- var companyId_1, companySetting, companyLicencesData_2, setQuery_1, i, companyLicenceType, j, err_2;
3979
+ var companyId, companySetting, companyLicencesData, setQuery, i, companyLicenceType, j, companyLicences, totalNoOfFeatureLicence, totalNoOfAppLicence, totalNoOfDomainLicence, c, licenceType, licenceName, companyLicenceTotal, i, companyLicenceType, j, err_2;
3946
3980
  return __generator(this, function (_a) {
3947
3981
  switch (_a.label) {
3948
3982
  case 0:
3949
- _a.trys.push([0, 2, , 3]);
3950
- companyId_1 = fieldsObj.CompanyID;
3951
- return [4 /*yield*/, dbMaster.collection("Company").findOne({ _id: companyId_1, 'IsActive': true }, { projection: { "Setting": 1 } })];
3983
+ _a.trys.push([0, 5, , 6]);
3984
+ companyId = fieldsObj.CompanyID;
3985
+ return [4 /*yield*/, dbMaster.collection("Company").findOne({ _id: companyId, 'IsActive': true }, { projection: { "Setting": 1 } })];
3952
3986
  case 1:
3953
3987
  companySetting = _a.sent();
3954
- if (companySetting) {
3955
- companyLicencesData_2 = (companySetting.Setting && companySetting.Setting.Licences) ? companySetting.Setting.Licences : {};
3956
- setQuery_1 = { 'Setting': (companySetting.Setting) ? companySetting.Setting : {} };
3957
- if (companyLicencesData_2[fieldsObj.LicenceType] == undefined) {
3958
- companyLicencesData_2[fieldsObj.LicenceType] = {};
3959
- }
3960
- if (Object.keys(companyLicencesData_2[fieldsObj.LicenceType]).includes(fieldsObj.LicenceName) == false) {
3961
- companyLicencesData_2[fieldsObj.LicenceType][fieldsObj.LicenceName] = {
3962
- "NoOfLicence": fieldsObj.NoOfLicence,
3963
- "NoOfLicenceConsumed": 0
3964
- };
3965
- }
3966
- for (i in companyLicencesData_2) {
3967
- companyLicenceType = companyLicencesData_2[i];
3968
- for (j in companyLicenceType) {
3969
- companyLicenceType[j].NoOfLicence = 0;
3970
- }
3988
+ if (!companySetting) return [3 /*break*/, 3];
3989
+ companyLicencesData = (companySetting.Setting && companySetting.Setting.Licences) ? companySetting.Setting.Licences : {};
3990
+ setQuery = { 'Setting': (companySetting.Setting) ? companySetting.Setting : {} };
3991
+ if (companyLicencesData[fieldsObj.LicenceType] == undefined) {
3992
+ companyLicencesData[fieldsObj.LicenceType] = {};
3993
+ }
3994
+ if (Object.keys(companyLicencesData[fieldsObj.LicenceType]).includes(fieldsObj.LicenceName) == false) {
3995
+ companyLicencesData[fieldsObj.LicenceType][fieldsObj.LicenceName] = {
3996
+ "NoOfLicence": fieldsObj.NoOfLicence,
3997
+ "NoOfLicenceConsumed": 0
3998
+ };
3999
+ }
4000
+ for (i in companyLicencesData) {
4001
+ companyLicenceType = companyLicencesData[i];
4002
+ for (j in companyLicenceType) {
4003
+ companyLicenceType[j].NoOfLicence = 0;
3971
4004
  }
3972
- dbMaster.collection('CompanyLicence').aggregate([
3973
- { $match: { CompanyID: companyId_1, Status: 'active', IsActive: true } },
4005
+ }
4006
+ return [4 /*yield*/, dbMaster.collection('CompanyLicence').aggregate([
4007
+ { $match: { CompanyID: companyId, Status: 'active', IsActive: true } },
3974
4008
  { $group: { _id: { "LicenceType": "$LicenceType", "LicenceName": "$LicenceName" }, Total: { $sum: "$NoOfLicence" } } }
3975
- ]).toArray(function (errUserAggregate, companyLicences) {
3976
- if (errUserAggregate) {
3977
- console.log(errUserAggregate, 'In company (' + companyId_1.toString() + '), Error occurred while syncing user licence consumed count.');
4009
+ ]).toArray()];
4010
+ case 2:
4011
+ companyLicences = _a.sent();
4012
+ if (companyLicences) {
4013
+ setQuery['TotalStandardLicence'] = 0;
4014
+ setQuery['TotalEnterpriseLicence'] = 0;
4015
+ totalNoOfFeatureLicence = 0;
4016
+ totalNoOfAppLicence = 0;
4017
+ totalNoOfDomainLicence = 0;
4018
+ for (c = 0; c < companyLicences.length; c++) {
4019
+ licenceType = companyLicences[c]._id['LicenceType'];
4020
+ licenceName = companyLicences[c]._id['LicenceName'];
4021
+ companyLicenceTotal = companyLicences[c].Total;
4022
+ if (licenceType == 'Master') {
4023
+ setQuery['Total' + licenceName + 'Licence'] = parseInt(companyLicenceTotal);
3978
4024
  }
3979
- else if (companyLicences) {
3980
- setQuery_1['TotalStandardLicence'] = 0;
3981
- setQuery_1['TotalEnterpriseLicence'] = 0;
3982
- var totalNoOfFeatureLicence = 0;
3983
- var totalNoOfAppLicence = 0;
3984
- //Added by Chetan on 22Feb2022, for domain licence
3985
- var totalNoOfDomainLicence = 0;
3986
- for (var c = 0; c < companyLicences.length; c++) {
3987
- var licenceType = companyLicences[c]._id['LicenceType'];
3988
- var licenceName = companyLicences[c]._id['LicenceName'];
3989
- var companyLicenceTotal = companyLicences[c].Total;
3990
- if (licenceType == 'Master') {
3991
- setQuery_1['Total' + licenceName + 'Licence'] = parseInt(companyLicenceTotal);
3992
- }
3993
- else if (licenceType == 'Feature') {
3994
- totalNoOfFeatureLicence += parseInt(companyLicenceTotal);
3995
- }
3996
- else if (licenceType == 'App') {
3997
- totalNoOfAppLicence += parseInt(companyLicenceTotal);
3998
- }
3999
- else if (licenceType == 'Domain') {
4000
- totalNoOfDomainLicence += parseInt(companyLicenceTotal); /*Added by Chetan on 22Feb2022, for domain licence*/
4001
- }
4002
- for (var i in companyLicencesData_2) {
4003
- if (i == licenceType) {
4004
- var companyLicenceType = companyLicencesData_2[i];
4005
- for (var j in companyLicenceType) {
4006
- if (j == licenceName) {
4007
- companyLicenceType[j].NoOfLicence = parseInt(companyLicenceTotal);
4008
- }
4009
- }
4025
+ else if (licenceType == 'Feature') {
4026
+ totalNoOfFeatureLicence += parseInt(companyLicenceTotal);
4027
+ }
4028
+ else if (licenceType == 'App') {
4029
+ totalNoOfAppLicence += parseInt(companyLicenceTotal);
4030
+ }
4031
+ else if (licenceType == 'Domain') {
4032
+ totalNoOfDomainLicence += parseInt(companyLicenceTotal); /*Added by Chetan on 22Feb2022, for domain licence*/
4033
+ }
4034
+ for (i in companyLicencesData) {
4035
+ if (i == licenceType) {
4036
+ companyLicenceType = companyLicencesData[i];
4037
+ for (j in companyLicenceType) {
4038
+ if (j == licenceName) {
4039
+ companyLicenceType[j].NoOfLicence = parseInt(companyLicenceTotal);
4010
4040
  }
4011
4041
  }
4012
4042
  }
4013
- setQuery_1['TotalFeatureLicence'] = totalNoOfFeatureLicence;
4014
- setQuery_1['TotalAppLicence'] = totalNoOfAppLicence;
4015
- //Added by Chetan on 22Feb2022, for domain licence
4016
- setQuery_1['TotalDomainLicence'] = totalNoOfDomainLicence;
4017
- setQuery_1.Setting["Licences"] = companyLicencesData_2;
4018
- dbMaster.collection('Company').updateOne({ _id: companyId_1, 'IsActive': true }, { $set: setQuery_1 });
4019
- }
4020
- else {
4021
- console.log('In company (' + companyId_1.toString() + '), Company Licence data not found while syncing company licence total count in Master Company.');
4022
4043
  }
4023
- });
4044
+ }
4045
+ setQuery['TotalFeatureLicence'] = totalNoOfFeatureLicence;
4046
+ setQuery['TotalAppLicence'] = totalNoOfAppLicence;
4047
+ //Added by Chetan on 22Feb2022, for domain licence
4048
+ setQuery['TotalDomainLicence'] = totalNoOfDomainLicence;
4049
+ setQuery.Setting["Licences"] = companyLicencesData;
4050
+ dbMaster.collection('Company').updateOne({ _id: companyId, 'IsActive': true }, { $set: setQuery });
4024
4051
  }
4025
4052
  else {
4026
- console.log('In company (' + companyId_1.toString() + '), Company data not found while syncing company licence total count in Master Company.');
4053
+ console.log('In company (' + companyId.toString() + '), Company Licence data not found while syncing company licence total count in Master Company.');
4027
4054
  }
4028
- return [3 /*break*/, 3];
4029
- case 2:
4055
+ return [3 /*break*/, 4];
4056
+ case 3:
4057
+ console.log('In company (' + companyId.toString() + '), Company data not found while syncing company licence total count in Master Company.');
4058
+ _a.label = 4;
4059
+ case 4: return [3 /*break*/, 6];
4060
+ case 5:
4030
4061
  err_2 = _a.sent();
4031
4062
  console.log(err_2, 'Error occurred while syncing company licence total count in Master Company.');
4032
- return [3 /*break*/, 3];
4033
- case 3: return [2 /*return*/];
4063
+ return [3 /*break*/, 6];
4064
+ case 6: return [2 /*return*/];
4034
4065
  }
4035
4066
  });
4036
4067
  });
@@ -4596,7 +4627,7 @@ function IsAnotherObjectField(pageData, fieldName) {
4596
4627
  function ValidateUserInput(options) {
4597
4628
  var _a, _b, _c;
4598
4629
  return __awaiter(this, void 0, void 0, function () {
4599
- var inputFields, fieldsJsonData, pageData, documentID, db, fiscalSettingData, action, objectSchema, objectName, pageFields, schemaFields, inputField, msg, _loop_18, _i, inputField_1, name_1, state_1, _loop_19, isValid, isValid, validateResp, _d, pageFields_1, pageField, state_2, countryData, err_3;
4630
+ var inputFields, fieldsJsonData, pageData, documentID, db, mdb, fiscalSettingData, action, objectSchema, objectName, pageFields, schemaFields, inputField, msg, _loop_18, _i, inputField_1, name_1, state_1, _loop_19, isValid, isValid, validateResp, _d, pageFields_1, pageField, state_2, countryData, err_3;
4600
4631
  return __generator(this, function (_e) {
4601
4632
  switch (_e.label) {
4602
4633
  case 0:
@@ -4606,6 +4637,7 @@ function ValidateUserInput(options) {
4606
4637
  pageData = options.pageData;
4607
4638
  documentID = options.objectID;
4608
4639
  db = options.db;
4640
+ mdb = options.mdb;
4609
4641
  return [4 /*yield*/, db.collection('Company').findOne({ IsActive: true }, { projection: { "Setting.FiscalFrom": 1, "Setting.FiscalMonth": 1, "Setting.DateFormat": 1 } })];
4610
4642
  case 1:
4611
4643
  fiscalSettingData = _e.sent();
@@ -4639,7 +4671,7 @@ function ValidateUserInput(options) {
4639
4671
  }
4640
4672
  }
4641
4673
  _loop_19 = function (pageField) {
4642
- var fieldName, fieldData, field, searchQuery, result, fld, _a, minValue, maxValue, filter, searchObj, result, searchObj, totalRecord, _b, schemaData, result, searchObj, result, schemaData, result, searchObj, totalRecord, regexpression, phone, files, _i, fieldData_1, obj, searchObj, totalRecord, searchObj, result, _c, fieldData_2, obj;
4674
+ var fieldName, fieldData, field, searchQuery, result, fld, _a, minValue, maxValue, filter, searchObj, dbConnection, result, searchObj, totalRecord, _b, schemaData, result, searchObj, result, schemaData, result, searchObj, totalRecord, regexpression, phone, files, _i, fieldData_1, obj, searchObj, totalRecord, searchObj, result, _c, fieldData_2, obj;
4643
4675
  return __generator(this, function (_d) {
4644
4676
  switch (_d.label) {
4645
4677
  case 0:
@@ -4802,7 +4834,8 @@ function ValidateUserInput(options) {
4802
4834
  searchObj.IsActive = true;
4803
4835
  }
4804
4836
  ;
4805
- return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
4837
+ dbConnection = (field.UseMasterDatabase && mdb) ? mdb : db;
4838
+ return [4 /*yield*/, dbConnection.collection(field.LookupObject).findOne(searchObj)];
4806
4839
  case 10:
4807
4840
  result = _d.sent();
4808
4841
  if (result == null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.333",
3
+ "version": "1.0.335",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {