@optimiser/common 1.0.318 → 1.0.320

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 +33 -57
  2. package/package.json +1 -1
@@ -194,7 +194,7 @@ exports.CheckUserProfileField = CheckUserProfileField;
194
194
  function GetPageFieldData(pageName, db, mdb, msp_d, next, callback) {
195
195
  db.collection("Page").findOne({ 'PageName': pageName }, function (err, pageData) {
196
196
  return __awaiter(this, void 0, void 0, function () {
197
- var response, hasAccess;
197
+ var hasAccess;
198
198
  return __generator(this, function (_a) {
199
199
  switch (_a.label) {
200
200
  case 0:
@@ -205,14 +205,8 @@ function GetPageFieldData(pageName, db, mdb, msp_d, next, callback) {
205
205
  callback(pageData);
206
206
  return [2 /*return*/];
207
207
  }
208
- return [4 /*yield*/, GetUserProfile(msp_d, db, mdb, next)];
209
- case 1:
210
- response = _a.sent();
211
- if (response && response.message == 'success') {
212
- pageData['UserProfile'] = response.data;
213
- }
214
208
  return [4 /*yield*/, CheckPageAuthentication(pageData, msp_d, db, mdb, next)];
215
- case 2:
209
+ case 1:
216
210
  hasAccess = _a.sent();
217
211
  if (!hasAccess) {
218
212
  callback('Unauthorised');
@@ -1013,7 +1007,7 @@ function SyncFieldInSameCollection(objectName, objectIDs, db) {
1013
1007
  var _this = this;
1014
1008
  return new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
1015
1009
  return __generator(this, function (_a) {
1016
- console.log("succass");
1010
+ console.log("success");
1017
1011
  try {
1018
1012
  db.collection("ObjectSchema").findOne({ 'Name': objectName }, function (err, objectSchema) {
1019
1013
  return __awaiter(this, void 0, void 0, function () {
@@ -3818,20 +3812,30 @@ exports.SyncUserLicenceConsumedCount = SyncUserLicenceConsumedCount;
3818
3812
  */
3819
3813
  function BroadCastEventToAllCompanyUsers(params) {
3820
3814
  try {
3821
- params.db.collection('User').find({
3822
- IsActive: true,
3823
- UserStatus: constants_1.default.USER_STATUS.ACTIVE
3824
- }, {
3825
- projection: { "_id": 1 }
3826
- }).toArray(function (err, res) {
3815
+ var aggregateArry = [];
3816
+ aggregateArry.push({
3817
+ $match: {
3818
+ 'IsActive': true,
3819
+ 'UserStatus': constants_1.default.USER_STATUS.ACTIVE
3820
+ }
3821
+ });
3822
+ if (params.Match != undefined) {
3823
+ aggregateArry.push({
3824
+ $match: params.Match
3825
+ });
3826
+ }
3827
+ aggregateArry.push({
3828
+ $project: { '_id': 1 }
3829
+ });
3830
+ params.db.collection('User').aggregate(aggregateArry, { "allowDiskUse": true }).toArray(function (err, usersData) {
3827
3831
  if (err) {
3828
3832
  console.log("Error while sending notification " + (params.EventName || "") + " to all company users. ==>", err);
3829
3833
  return;
3830
3834
  }
3831
- else if (res && res.length > 0) {
3832
- for (var i = 0; i < res.length; i++) {
3835
+ else if (usersData && usersData.length > 0) {
3836
+ for (var i = 0; i < usersData.length; i++) {
3833
3837
  //not sending notification to sender
3834
- if (params.UserID && params.UserID.toString() == res[i]._id.toString()) {
3838
+ if (params.UserID && params.UserID.toString() == usersData[i]._id.toString()) {
3835
3839
  continue;
3836
3840
  }
3837
3841
  //params.userID to handle
@@ -3843,9 +3847,9 @@ function BroadCastEventToAllCompanyUsers(params) {
3843
3847
  var socketObjectData = {
3844
3848
  eventType: eventItem.EventName,
3845
3849
  data: eventItem.EventData,
3846
- userId: res[i]._id.toString()
3850
+ userId: usersData[i]._id.toString()
3847
3851
  };
3848
- //socketUtility.TriggerSockerEvent(req, res[i]._id.toString(), eventName, data);
3852
+ //socketUtility.TriggerSockerEvent(req, usersData[i]._id.toString(), eventName, data);
3849
3853
  params.event.CreateEvent(null, null, { SocketObj: socketObjectData }).then(function (socketResult) {
3850
3854
  if (socketResult) {
3851
3855
  console.log("Success");
@@ -3876,26 +3880,6 @@ exports.BroadCastEventToAllCompanyUsers = BroadCastEventToAllCompanyUsers;
3876
3880
  * @description check before add update or delete operation
3877
3881
  */
3878
3882
  function CheckDataPermission(fieldsObj, pageData, profileData, actionType) {
3879
- //actionType value Will be add or edit
3880
- if (pageData.Fields != undefined) {
3881
- for (var i = 0; i < pageData.Fields.length; i++) {
3882
- var fld = pageData.Fields[i];
3883
- var disableON = fld.DisableON;
3884
- if (disableON !== undefined && (disableON == 'both' || (disableON == actionType)))
3885
- delete fieldsObj[fld.Name];
3886
- }
3887
- }
3888
- if (pageData.Groups != undefined) {
3889
- for (var g = 0; g < pageData.Groups.length; g++) {
3890
- var group = pageData.Groups[g];
3891
- for (var i = 0; i < group.Fields.length; i++) {
3892
- var fld = group.Fields[i];
3893
- var disableON = fld.DisableON;
3894
- if (disableON !== undefined && (disableON == 'both' || (disableON == actionType)))
3895
- delete fieldsObj[fld.Name];
3896
- }
3897
- }
3898
- }
3899
3883
  if (profileData && profileData.Fields) {
3900
3884
  for (var i = 0; i < profileData.Fields.length; i++) {
3901
3885
  var obj = profileData.Fields[i];
@@ -4297,26 +4281,19 @@ exports.GetUserProfile = GetUserProfile;
4297
4281
  function CheckPageAuthentication(pageData, msp_d, db, mdb, next) {
4298
4282
  var _a, _b;
4299
4283
  return __awaiter(this, void 0, void 0, function () {
4300
- var hasAccess, userProfile, response, auth, i, moduleData;
4284
+ var hasAccess, response, userProfile, auth, i, moduleData;
4301
4285
  return __generator(this, function (_c) {
4302
4286
  switch (_c.label) {
4303
4287
  case 0:
4304
4288
  hasAccess = false;
4305
4289
  if (!(pageData.IsPermissionRequired == false)) return [3 /*break*/, 1];
4306
4290
  hasAccess = true;
4307
- return [3 /*break*/, 5];
4308
- case 1:
4309
- userProfile = void 0;
4310
- if (!pageData.UserProfile) return [3 /*break*/, 2];
4311
- userProfile = pageData.UserProfile;
4312
- return [3 /*break*/, 4];
4313
- case 2: return [4 /*yield*/, GetUserProfile(msp_d, db, mdb, next)];
4314
- case 3:
4291
+ return [3 /*break*/, 3];
4292
+ case 1: return [4 /*yield*/, GetUserProfile(msp_d, db, mdb, next)];
4293
+ case 2:
4315
4294
  response = _c.sent();
4316
- userProfile = response === null || response === void 0 ? void 0 : response.data;
4317
- _c.label = 4;
4318
- case 4:
4319
- if (userProfile) {
4295
+ if (response && response.message == 'success') {
4296
+ userProfile = response.data;
4320
4297
  auth = userProfile.Permissions;
4321
4298
  for (i = 0; i < auth.length; i++) {
4322
4299
  moduleData = auth[i].ModuleData;
@@ -4329,11 +4306,10 @@ function CheckPageAuthentication(pageData, msp_d, db, mdb, next) {
4329
4306
  }
4330
4307
  }
4331
4308
  else {
4332
- console.log('User Profile data is not found while checking Page authentication.');
4333
- hasAccess = false;
4309
+ console.log(response === null || response === void 0 ? void 0 : response.message);
4334
4310
  }
4335
- _c.label = 5;
4336
- case 5: return [2 /*return*/, hasAccess];
4311
+ _c.label = 3;
4312
+ case 3: return [2 /*return*/, hasAccess];
4337
4313
  }
4338
4314
  });
4339
4315
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.318",
3
+ "version": "1.0.320",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {