@optimiser/common 1.0.332 → 1.0.334

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 +178 -126
  2. package/package.json +1 -1
@@ -491,7 +491,32 @@ function GetFieldDetail(objectName, fieldName, db, callback, next) {
491
491
  callback(data.Fields[0]);
492
492
  }
493
493
  else {
494
- callback([]);
494
+ //if field not found then check in collection field
495
+ db.collection('ObjectSchema').findOne({ 'Name': objectName, "Fields.UIDataType": "collection", "Fields.Fields.Name": fieldName }, { projection: { _id: 0, Fields: 1 } }, function (err, data) {
496
+ if (err) {
497
+ next(err);
498
+ }
499
+ else if (data && data.Fields && data.Fields.length) {
500
+ var field = undefined;
501
+ var collectionFields = data.Fields.filter(function (x) { return x.UIDataType == "collection"; });
502
+ if (collectionFields) {
503
+ for (var i = 0; i < collectionFields.length; i++) {
504
+ var colField = collectionFields[0];
505
+ if (colField.Fields) {
506
+ field = colField.Fields.find(function (x) { return x.Name == fieldName; });
507
+ break;
508
+ }
509
+ }
510
+ }
511
+ if (field)
512
+ callback(field);
513
+ else
514
+ callback({});
515
+ }
516
+ else {
517
+ callback({});
518
+ }
519
+ });
495
520
  }
496
521
  });
497
522
  }
@@ -3746,73 +3771,101 @@ function UpdateTagCount(tagids, objectName, db, params) {
3746
3771
  }
3747
3772
  function SyncUserLicenceConsumedCount(msp_d, db, dbMaster) {
3748
3773
  return __awaiter(this, void 0, void 0, function () {
3749
- 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;
3750
3775
  return __generator(this, function (_a) {
3751
3776
  switch (_a.label) {
3752
3777
  case 0:
3753
- _a.trys.push([0, 2, , 3]);
3778
+ _a.trys.push([0, 8, , 9]);
3754
3779
  return [4 /*yield*/, dbMaster.collection("Company").findOne({ _id: new mongodb_1.ObjectId(msp_d.ci), 'IsActive': true }, { projection: { "Setting.Licences": 1 } })];
3755
3780
  case 1:
3756
3781
  companySetting = _a.sent();
3757
- if (companySetting && companySetting.Setting) {
3758
- companyLicencesData_1 = (companySetting.Setting.Licences) ? companySetting.Setting.Licences : {};
3759
- if (isEmptyObj(companyLicencesData_1) == false) {
3760
- for (i in companyLicencesData_1) {
3761
- /*Added by Chetan on 07-Mar-2022, Not necessary for Domain Licence*/
3762
- if (i != "Domain") {
3763
- 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];
3764
3808
  for (j in companyLicenceType) {
3765
- companyLicenceType[j].NoOfLicenceConsumed = 0;
3809
+ if (j == licenceName) {
3810
+ companyLicenceType[j].NoOfLicenceConsumed = licenceTotal;
3811
+ }
3766
3812
  }
3767
3813
  }
3768
3814
  }
3769
- db.collection('UserLicence').aggregate([
3770
- { $match: { Status: 'active', IsActive: true } },
3771
- { $group: { _id: { "LicenceType": "$LicenceType", "LicenceName": "$LicenceName" }, Total: { $sum: 1 } } }
3772
- ]).toArray(function (errUserAggregate, userLicenceData) {
3773
- if (errUserAggregate) {
3774
- console.log(errUserAggregate, 'In company (' + msp_d.ci + '), Error occurred while syncing user licence consumed count.');
3775
- }
3776
- else if (userLicenceData) {
3777
- for (var u = 0; u < userLicenceData.length; u++) {
3778
- var licenceType = userLicenceData[u]._id['LicenceType'];
3779
- var licenceName = userLicenceData[u]._id['LicenceName'];
3780
- var licenceTotal = userLicenceData[u].Total;
3781
- for (var i in companyLicencesData_1) {
3782
- if (i == licenceType) {
3783
- var companyLicenceType = companyLicencesData_1[i];
3784
- for (var j in companyLicenceType) {
3785
- if (j == licenceName) {
3786
- companyLicenceType[j].NoOfLicenceConsumed = licenceTotal;
3787
- }
3788
- }
3789
- }
3790
- }
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
+ for (u = 0; u < comLicenceInUserLicence.length; u++) {
3834
+ licenceID = comLicenceInUserLicence[u]._id['CompanyLicenceID'];
3835
+ licenceTotal = comLicenceInUserLicence[u].Total;
3836
+ if (licenceID) {
3837
+ bulkLicenceOps.push({
3838
+ updateOne: {
3839
+ filter: { '_id': licenceID },
3840
+ update: [
3841
+ { $set: { 'NoOfLicenceConsumed': licenceTotal } },
3842
+ { $set: { 'NoOfRemainingLicence': { $subtract: ["$NoOfLicence", "$NoOfLicenceConsumed"] } } }
3843
+ ]
3791
3844
  }
3792
- dbMaster.collection('Company').updateOne({ _id: new mongodb_1.ObjectId(msp_d.ci), 'IsActive': true }, {
3793
- $set: {
3794
- "Setting.Licences": companyLicencesData_1
3795
- }
3796
- });
3797
- }
3798
- else {
3799
- console.log('In company (' + msp_d.ci + '), User Licence data not found while syncing user licence consumed count.');
3800
- }
3801
- });
3845
+ });
3846
+ }
3802
3847
  }
3803
- else {
3804
- console.log('Licence data not found in company (' + msp_d.ci + ') setting while syncing user licence consumed count.');
3848
+ if (bulkLicenceOps.length) {
3849
+ dbMaster.collection('CompanyLicence').bulkWrite(bulkLicenceOps);
3805
3850
  }
3806
3851
  }
3807
3852
  else {
3808
- console.log('Company (' + msp_d.ci + ') data not found while syncing user licence consumed count.');
3853
+ console.log('In company (' + msp_d.ci + '), copmany licence data not found in user licence while syncing user licence consumed count.');
3809
3854
  }
3810
- return [3 /*break*/, 3];
3811
- case 2:
3855
+ return [3 /*break*/, 5];
3856
+ case 4:
3857
+ console.log('Licence data not found in company (' + msp_d.ci + ') setting while syncing user licence consumed count.');
3858
+ _a.label = 5;
3859
+ case 5: return [3 /*break*/, 7];
3860
+ case 6:
3861
+ console.log('Company (' + msp_d.ci + ') data not found while syncing user licence consumed count.');
3862
+ _a.label = 7;
3863
+ case 7: return [3 /*break*/, 9];
3864
+ case 8:
3812
3865
  err_1 = _a.sent();
3813
- console.log(err_1, 'Error occurred while syncing user licence consumed count.');
3814
- return [3 /*break*/, 3];
3815
- case 3: return [2 /*return*/];
3866
+ console.log('Error occurred while syncing user licence consumed count.', err_1);
3867
+ return [3 /*break*/, 9];
3868
+ case 9: return [2 /*return*/];
3816
3869
  }
3817
3870
  });
3818
3871
  });
@@ -3917,95 +3970,92 @@ exports.CheckDataPermission = CheckDataPermission;
3917
3970
  */
3918
3971
  function SyncCompanyLicenceInMasterCompanyAfterAdd(fieldsObj, dbMaster) {
3919
3972
  return __awaiter(this, void 0, void 0, function () {
3920
- var companyId_1, companySetting, companyLicencesData_2, setQuery_1, i, companyLicenceType, j, err_2;
3973
+ var companyId, companySetting, companyLicencesData, setQuery, i, companyLicenceType, j, companyLicences, totalNoOfFeatureLicence, totalNoOfAppLicence, totalNoOfDomainLicence, c, licenceType, licenceName, companyLicenceTotal, i, companyLicenceType, j, err_2;
3921
3974
  return __generator(this, function (_a) {
3922
3975
  switch (_a.label) {
3923
3976
  case 0:
3924
- _a.trys.push([0, 2, , 3]);
3925
- companyId_1 = fieldsObj.CompanyID;
3926
- return [4 /*yield*/, dbMaster.collection("Company").findOne({ _id: companyId_1, 'IsActive': true }, { projection: { "Setting": 1 } })];
3977
+ _a.trys.push([0, 5, , 6]);
3978
+ companyId = fieldsObj.CompanyID;
3979
+ return [4 /*yield*/, dbMaster.collection("Company").findOne({ _id: companyId, 'IsActive': true }, { projection: { "Setting": 1 } })];
3927
3980
  case 1:
3928
3981
  companySetting = _a.sent();
3929
- if (companySetting) {
3930
- companyLicencesData_2 = (companySetting.Setting && companySetting.Setting.Licences) ? companySetting.Setting.Licences : {};
3931
- setQuery_1 = { 'Setting': (companySetting.Setting) ? companySetting.Setting : {} };
3932
- if (companyLicencesData_2[fieldsObj.LicenceType] == undefined) {
3933
- companyLicencesData_2[fieldsObj.LicenceType] = {};
3934
- }
3935
- if (Object.keys(companyLicencesData_2[fieldsObj.LicenceType]).includes(fieldsObj.LicenceName) == false) {
3936
- companyLicencesData_2[fieldsObj.LicenceType][fieldsObj.LicenceName] = {
3937
- "NoOfLicence": fieldsObj.NoOfLicence,
3938
- "NoOfLicenceConsumed": 0
3939
- };
3940
- }
3941
- for (i in companyLicencesData_2) {
3942
- companyLicenceType = companyLicencesData_2[i];
3943
- for (j in companyLicenceType) {
3944
- companyLicenceType[j].NoOfLicence = 0;
3945
- }
3982
+ if (!companySetting) return [3 /*break*/, 3];
3983
+ companyLicencesData = (companySetting.Setting && companySetting.Setting.Licences) ? companySetting.Setting.Licences : {};
3984
+ setQuery = { 'Setting': (companySetting.Setting) ? companySetting.Setting : {} };
3985
+ if (companyLicencesData[fieldsObj.LicenceType] == undefined) {
3986
+ companyLicencesData[fieldsObj.LicenceType] = {};
3987
+ }
3988
+ if (Object.keys(companyLicencesData[fieldsObj.LicenceType]).includes(fieldsObj.LicenceName) == false) {
3989
+ companyLicencesData[fieldsObj.LicenceType][fieldsObj.LicenceName] = {
3990
+ "NoOfLicence": fieldsObj.NoOfLicence,
3991
+ "NoOfLicenceConsumed": 0
3992
+ };
3993
+ }
3994
+ for (i in companyLicencesData) {
3995
+ companyLicenceType = companyLicencesData[i];
3996
+ for (j in companyLicenceType) {
3997
+ companyLicenceType[j].NoOfLicence = 0;
3946
3998
  }
3947
- dbMaster.collection('CompanyLicence').aggregate([
3948
- { $match: { CompanyID: companyId_1, Status: 'active', IsActive: true } },
3999
+ }
4000
+ return [4 /*yield*/, dbMaster.collection('CompanyLicence').aggregate([
4001
+ { $match: { CompanyID: companyId, Status: 'active', IsActive: true } },
3949
4002
  { $group: { _id: { "LicenceType": "$LicenceType", "LicenceName": "$LicenceName" }, Total: { $sum: "$NoOfLicence" } } }
3950
- ]).toArray(function (errUserAggregate, companyLicences) {
3951
- if (errUserAggregate) {
3952
- console.log(errUserAggregate, 'In company (' + companyId_1.toString() + '), Error occurred while syncing user licence consumed count.');
4003
+ ]).toArray()];
4004
+ case 2:
4005
+ companyLicences = _a.sent();
4006
+ if (companyLicences) {
4007
+ setQuery['TotalStandardLicence'] = 0;
4008
+ setQuery['TotalEnterpriseLicence'] = 0;
4009
+ totalNoOfFeatureLicence = 0;
4010
+ totalNoOfAppLicence = 0;
4011
+ totalNoOfDomainLicence = 0;
4012
+ for (c = 0; c < companyLicences.length; c++) {
4013
+ licenceType = companyLicences[c]._id['LicenceType'];
4014
+ licenceName = companyLicences[c]._id['LicenceName'];
4015
+ companyLicenceTotal = companyLicences[c].Total;
4016
+ if (licenceType == 'Master') {
4017
+ setQuery['Total' + licenceName + 'Licence'] = parseInt(companyLicenceTotal);
3953
4018
  }
3954
- else if (companyLicences) {
3955
- setQuery_1['TotalStandardLicence'] = 0;
3956
- setQuery_1['TotalEnterpriseLicence'] = 0;
3957
- var totalNoOfFeatureLicence = 0;
3958
- var totalNoOfAppLicence = 0;
3959
- //Added by Chetan on 22Feb2022, for domain licence
3960
- var totalNoOfDomainLicence = 0;
3961
- for (var c = 0; c < companyLicences.length; c++) {
3962
- var licenceType = companyLicences[c]._id['LicenceType'];
3963
- var licenceName = companyLicences[c]._id['LicenceName'];
3964
- var companyLicenceTotal = companyLicences[c].Total;
3965
- if (licenceType == 'Master') {
3966
- setQuery_1['Total' + licenceName + 'Licence'] = parseInt(companyLicenceTotal);
3967
- }
3968
- else if (licenceType == 'Feature') {
3969
- totalNoOfFeatureLicence += parseInt(companyLicenceTotal);
3970
- }
3971
- else if (licenceType == 'App') {
3972
- totalNoOfAppLicence += parseInt(companyLicenceTotal);
3973
- }
3974
- else if (licenceType == 'Domain') {
3975
- totalNoOfDomainLicence += parseInt(companyLicenceTotal); /*Added by Chetan on 22Feb2022, for domain licence*/
3976
- }
3977
- for (var i in companyLicencesData_2) {
3978
- if (i == licenceType) {
3979
- var companyLicenceType = companyLicencesData_2[i];
3980
- for (var j in companyLicenceType) {
3981
- if (j == licenceName) {
3982
- companyLicenceType[j].NoOfLicence = parseInt(companyLicenceTotal);
3983
- }
3984
- }
4019
+ else if (licenceType == 'Feature') {
4020
+ totalNoOfFeatureLicence += parseInt(companyLicenceTotal);
4021
+ }
4022
+ else if (licenceType == 'App') {
4023
+ totalNoOfAppLicence += parseInt(companyLicenceTotal);
4024
+ }
4025
+ else if (licenceType == 'Domain') {
4026
+ totalNoOfDomainLicence += parseInt(companyLicenceTotal); /*Added by Chetan on 22Feb2022, for domain licence*/
4027
+ }
4028
+ for (i in companyLicencesData) {
4029
+ if (i == licenceType) {
4030
+ companyLicenceType = companyLicencesData[i];
4031
+ for (j in companyLicenceType) {
4032
+ if (j == licenceName) {
4033
+ companyLicenceType[j].NoOfLicence = parseInt(companyLicenceTotal);
3985
4034
  }
3986
4035
  }
3987
4036
  }
3988
- setQuery_1['TotalFeatureLicence'] = totalNoOfFeatureLicence;
3989
- setQuery_1['TotalAppLicence'] = totalNoOfAppLicence;
3990
- //Added by Chetan on 22Feb2022, for domain licence
3991
- setQuery_1['TotalDomainLicence'] = totalNoOfDomainLicence;
3992
- setQuery_1.Setting["Licences"] = companyLicencesData_2;
3993
- dbMaster.collection('Company').updateOne({ _id: companyId_1, 'IsActive': true }, { $set: setQuery_1 });
3994
- }
3995
- else {
3996
- console.log('In company (' + companyId_1.toString() + '), Company Licence data not found while syncing company licence total count in Master Company.');
3997
4037
  }
3998
- });
4038
+ }
4039
+ setQuery['TotalFeatureLicence'] = totalNoOfFeatureLicence;
4040
+ setQuery['TotalAppLicence'] = totalNoOfAppLicence;
4041
+ //Added by Chetan on 22Feb2022, for domain licence
4042
+ setQuery['TotalDomainLicence'] = totalNoOfDomainLicence;
4043
+ setQuery.Setting["Licences"] = companyLicencesData;
4044
+ dbMaster.collection('Company').updateOne({ _id: companyId, 'IsActive': true }, { $set: setQuery });
3999
4045
  }
4000
4046
  else {
4001
- console.log('In company (' + companyId_1.toString() + '), Company data not found while syncing company licence total count in Master Company.');
4047
+ console.log('In company (' + companyId.toString() + '), Company Licence data not found while syncing company licence total count in Master Company.');
4002
4048
  }
4003
- return [3 /*break*/, 3];
4004
- case 2:
4049
+ return [3 /*break*/, 4];
4050
+ case 3:
4051
+ console.log('In company (' + companyId.toString() + '), Company data not found while syncing company licence total count in Master Company.');
4052
+ _a.label = 4;
4053
+ case 4: return [3 /*break*/, 6];
4054
+ case 5:
4005
4055
  err_2 = _a.sent();
4006
4056
  console.log(err_2, 'Error occurred while syncing company licence total count in Master Company.');
4007
- return [3 /*break*/, 3];
4008
- case 3: return [2 /*return*/];
4057
+ return [3 /*break*/, 6];
4058
+ case 6: return [2 /*return*/];
4009
4059
  }
4010
4060
  });
4011
4061
  });
@@ -4571,7 +4621,7 @@ function IsAnotherObjectField(pageData, fieldName) {
4571
4621
  function ValidateUserInput(options) {
4572
4622
  var _a, _b, _c;
4573
4623
  return __awaiter(this, void 0, void 0, function () {
4574
- 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;
4624
+ 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;
4575
4625
  return __generator(this, function (_e) {
4576
4626
  switch (_e.label) {
4577
4627
  case 0:
@@ -4581,6 +4631,7 @@ function ValidateUserInput(options) {
4581
4631
  pageData = options.pageData;
4582
4632
  documentID = options.objectID;
4583
4633
  db = options.db;
4634
+ mdb = options.mdb;
4584
4635
  return [4 /*yield*/, db.collection('Company').findOne({ IsActive: true }, { projection: { "Setting.FiscalFrom": 1, "Setting.FiscalMonth": 1, "Setting.DateFormat": 1 } })];
4585
4636
  case 1:
4586
4637
  fiscalSettingData = _e.sent();
@@ -4614,7 +4665,7 @@ function ValidateUserInput(options) {
4614
4665
  }
4615
4666
  }
4616
4667
  _loop_19 = function (pageField) {
4617
- 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;
4668
+ 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;
4618
4669
  return __generator(this, function (_d) {
4619
4670
  switch (_d.label) {
4620
4671
  case 0:
@@ -4777,7 +4828,8 @@ function ValidateUserInput(options) {
4777
4828
  searchObj.IsActive = true;
4778
4829
  }
4779
4830
  ;
4780
- return [4 /*yield*/, db.collection(field.LookupObject).findOne(searchObj)];
4831
+ dbConnection = (field.UseMasterDatabase && mdb) ? mdb : db;
4832
+ return [4 /*yield*/, dbConnection.collection(field.LookupObject).findOne(searchObj)];
4781
4833
  case 10:
4782
4834
  result = _d.sent();
4783
4835
  if (result == null) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.332",
3
+ "version": "1.0.334",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {