@optimiser/common 1.0.333 → 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.
- package/dist/lib/utility.js +152 -125
- package/package.json +1 -1
package/dist/lib/utility.js
CHANGED
|
@@ -3771,73 +3771,101 @@ 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,
|
|
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,
|
|
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
|
-
|
|
3784
|
-
|
|
3785
|
-
|
|
3786
|
-
|
|
3787
|
-
|
|
3788
|
-
|
|
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
|
-
|
|
3809
|
+
if (j == licenceName) {
|
|
3810
|
+
companyLicenceType[j].NoOfLicenceConsumed = licenceTotal;
|
|
3811
|
+
}
|
|
3791
3812
|
}
|
|
3792
3813
|
}
|
|
3793
3814
|
}
|
|
3794
|
-
|
|
3795
|
-
|
|
3796
|
-
|
|
3797
|
-
|
|
3798
|
-
|
|
3799
|
-
|
|
3800
|
-
|
|
3801
|
-
|
|
3802
|
-
|
|
3803
|
-
|
|
3804
|
-
|
|
3805
|
-
|
|
3806
|
-
|
|
3807
|
-
|
|
3808
|
-
|
|
3809
|
-
|
|
3810
|
-
|
|
3811
|
-
|
|
3812
|
-
|
|
3813
|
-
|
|
3814
|
-
|
|
3815
|
-
|
|
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
|
+
]
|
|
3816
3844
|
}
|
|
3817
|
-
|
|
3818
|
-
|
|
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
|
-
});
|
|
3845
|
+
});
|
|
3846
|
+
}
|
|
3827
3847
|
}
|
|
3828
|
-
|
|
3829
|
-
|
|
3848
|
+
if (bulkLicenceOps.length) {
|
|
3849
|
+
dbMaster.collection('CompanyLicence').bulkWrite(bulkLicenceOps);
|
|
3830
3850
|
}
|
|
3831
3851
|
}
|
|
3832
3852
|
else {
|
|
3833
|
-
console.log('
|
|
3853
|
+
console.log('In company (' + msp_d.ci + '), copmany licence data not found in user licence while syncing user licence consumed count.');
|
|
3834
3854
|
}
|
|
3835
|
-
return [3 /*break*/,
|
|
3836
|
-
case
|
|
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:
|
|
3837
3865
|
err_1 = _a.sent();
|
|
3838
|
-
console.log(
|
|
3839
|
-
return [3 /*break*/,
|
|
3840
|
-
case
|
|
3866
|
+
console.log('Error occurred while syncing user licence consumed count.', err_1);
|
|
3867
|
+
return [3 /*break*/, 9];
|
|
3868
|
+
case 9: return [2 /*return*/];
|
|
3841
3869
|
}
|
|
3842
3870
|
});
|
|
3843
3871
|
});
|
|
@@ -3942,95 +3970,92 @@ exports.CheckDataPermission = CheckDataPermission;
|
|
|
3942
3970
|
*/
|
|
3943
3971
|
function SyncCompanyLicenceInMasterCompanyAfterAdd(fieldsObj, dbMaster) {
|
|
3944
3972
|
return __awaiter(this, void 0, void 0, function () {
|
|
3945
|
-
var
|
|
3973
|
+
var companyId, companySetting, companyLicencesData, setQuery, i, companyLicenceType, j, companyLicences, totalNoOfFeatureLicence, totalNoOfAppLicence, totalNoOfDomainLicence, c, licenceType, licenceName, companyLicenceTotal, i, companyLicenceType, j, err_2;
|
|
3946
3974
|
return __generator(this, function (_a) {
|
|
3947
3975
|
switch (_a.label) {
|
|
3948
3976
|
case 0:
|
|
3949
|
-
_a.trys.push([0,
|
|
3950
|
-
|
|
3951
|
-
return [4 /*yield*/, dbMaster.collection("Company").findOne({ _id:
|
|
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 } })];
|
|
3952
3980
|
case 1:
|
|
3953
3981
|
companySetting = _a.sent();
|
|
3954
|
-
if (companySetting)
|
|
3955
|
-
|
|
3956
|
-
|
|
3957
|
-
|
|
3958
|
-
|
|
3959
|
-
|
|
3960
|
-
|
|
3961
|
-
|
|
3962
|
-
|
|
3963
|
-
|
|
3964
|
-
|
|
3965
|
-
|
|
3966
|
-
|
|
3967
|
-
|
|
3968
|
-
|
|
3969
|
-
|
|
3970
|
-
}
|
|
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;
|
|
3971
3998
|
}
|
|
3972
|
-
|
|
3973
|
-
|
|
3999
|
+
}
|
|
4000
|
+
return [4 /*yield*/, dbMaster.collection('CompanyLicence').aggregate([
|
|
4001
|
+
{ $match: { CompanyID: companyId, Status: 'active', IsActive: true } },
|
|
3974
4002
|
{ $group: { _id: { "LicenceType": "$LicenceType", "LicenceName": "$LicenceName" }, Total: { $sum: "$NoOfLicence" } } }
|
|
3975
|
-
]).toArray(
|
|
3976
|
-
|
|
3977
|
-
|
|
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);
|
|
3978
4018
|
}
|
|
3979
|
-
else if (
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
|
|
3990
|
-
|
|
3991
|
-
|
|
3992
|
-
|
|
3993
|
-
|
|
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
|
-
}
|
|
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);
|
|
4010
4034
|
}
|
|
4011
4035
|
}
|
|
4012
4036
|
}
|
|
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
4037
|
}
|
|
4023
|
-
}
|
|
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 });
|
|
4024
4045
|
}
|
|
4025
4046
|
else {
|
|
4026
|
-
console.log('In company (' +
|
|
4047
|
+
console.log('In company (' + companyId.toString() + '), Company Licence data not found while syncing company licence total count in Master Company.');
|
|
4027
4048
|
}
|
|
4028
|
-
return [3 /*break*/,
|
|
4029
|
-
case
|
|
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:
|
|
4030
4055
|
err_2 = _a.sent();
|
|
4031
4056
|
console.log(err_2, 'Error occurred while syncing company licence total count in Master Company.');
|
|
4032
|
-
return [3 /*break*/,
|
|
4033
|
-
case
|
|
4057
|
+
return [3 /*break*/, 6];
|
|
4058
|
+
case 6: return [2 /*return*/];
|
|
4034
4059
|
}
|
|
4035
4060
|
});
|
|
4036
4061
|
});
|
|
@@ -4596,7 +4621,7 @@ function IsAnotherObjectField(pageData, fieldName) {
|
|
|
4596
4621
|
function ValidateUserInput(options) {
|
|
4597
4622
|
var _a, _b, _c;
|
|
4598
4623
|
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;
|
|
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;
|
|
4600
4625
|
return __generator(this, function (_e) {
|
|
4601
4626
|
switch (_e.label) {
|
|
4602
4627
|
case 0:
|
|
@@ -4606,6 +4631,7 @@ function ValidateUserInput(options) {
|
|
|
4606
4631
|
pageData = options.pageData;
|
|
4607
4632
|
documentID = options.objectID;
|
|
4608
4633
|
db = options.db;
|
|
4634
|
+
mdb = options.mdb;
|
|
4609
4635
|
return [4 /*yield*/, db.collection('Company').findOne({ IsActive: true }, { projection: { "Setting.FiscalFrom": 1, "Setting.FiscalMonth": 1, "Setting.DateFormat": 1 } })];
|
|
4610
4636
|
case 1:
|
|
4611
4637
|
fiscalSettingData = _e.sent();
|
|
@@ -4639,7 +4665,7 @@ function ValidateUserInput(options) {
|
|
|
4639
4665
|
}
|
|
4640
4666
|
}
|
|
4641
4667
|
_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;
|
|
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;
|
|
4643
4669
|
return __generator(this, function (_d) {
|
|
4644
4670
|
switch (_d.label) {
|
|
4645
4671
|
case 0:
|
|
@@ -4802,7 +4828,8 @@ function ValidateUserInput(options) {
|
|
|
4802
4828
|
searchObj.IsActive = true;
|
|
4803
4829
|
}
|
|
4804
4830
|
;
|
|
4805
|
-
|
|
4831
|
+
dbConnection = (field.UseMasterDatabase && mdb) ? mdb : db;
|
|
4832
|
+
return [4 /*yield*/, dbConnection.collection(field.LookupObject).findOne(searchObj)];
|
|
4806
4833
|
case 10:
|
|
4807
4834
|
result = _d.sent();
|
|
4808
4835
|
if (result == null) {
|