@optimiser/common 1.0.371 → 1.0.373

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/event.js +31 -12
  2. package/package.json +1 -1
package/dist/lib/event.js CHANGED
@@ -77,14 +77,15 @@ var Event = /** @class */ (function () {
77
77
  return __generator(this, function (_a) {
78
78
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
79
79
  var notificationDataObj, userObj, userDeviceInfoObj, notificationCount, message, response, error_1, uniqueID, params;
80
- return __generator(this, function (_a) {
81
- switch (_a.label) {
80
+ var _a, _b;
81
+ return __generator(this, function (_c) {
82
+ switch (_c.label) {
82
83
  case 0:
83
84
  if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 9];
84
85
  notificationDataObj = data.PushNotificationObj;
85
86
  return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
86
87
  case 1:
87
- userObj = _a.sent();
88
+ userObj = _c.sent();
88
89
  if (userObj && userObj.endpoint && userObj.keys && data.PushNotificationObj) {
89
90
  data.PushNotificationObj["endpoint"] = userObj.endpoint;
90
91
  data.PushNotificationObj["keys"] = userObj.keys;
@@ -96,13 +97,31 @@ var Event = /** @class */ (function () {
96
97
  if (!this.FCMMobileServiceAccountKey) return [3 /*break*/, 8];
97
98
  return [4 /*yield*/, db.collection('UserMobileNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
98
99
  case 2:
99
- userDeviceInfoObj = _a.sent();
100
+ userDeviceInfoObj = _c.sent();
100
101
  console.log("userDeviceInfoObj", userDeviceInfoObj);
101
102
  if (!(userDeviceInfoObj && userDeviceInfoObj.deviceToken && notificationDataObj)) return [3 /*break*/, 7];
102
- return [4 /*yield*/, db.collection('Notification').countDocuments({ 'Users.UserID': new mongodb_1.ObjectId(userId), 'IsActive': true, "Users.IsNew": true })];
103
+ return [4 /*yield*/, db.collection('Notification').aggregate([{
104
+ $match: {
105
+ 'Users': { $elemMatch: { 'UserID': new mongodb_1.ObjectId(userId) } },
106
+ 'IsActive': true
107
+ }
108
+ }, {
109
+ $facet: {
110
+ TotalUnseenNoti: [{
111
+ $unwind: "$Users"
112
+ }, {
113
+ $match: { "Users.UserID": new mongodb_1.ObjectId(userId), "Users.IsNew": true }
114
+ }, {
115
+ $count: 'count'
116
+ }]
117
+ }
118
+ }]).toArray()];
103
119
  case 3:
104
- notificationCount = _a.sent();
105
- notificationDataObj['notificationCount'] = notificationCount;
120
+ notificationCount = _c.sent();
121
+ if ((notificationDataObj === null || notificationDataObj === void 0 ? void 0 : notificationDataObj.isBackgroundPushnotification) != true) {
122
+ console.log("notificationCount", (_a = notificationCount[0].TotalUnseenNoti[0]) === null || _a === void 0 ? void 0 : _a.count);
123
+ notificationDataObj['notificationCount'] = (_b = notificationCount[0].TotalUnseenNoti[0]) === null || _b === void 0 ? void 0 : _b.count;
124
+ }
106
125
  message = {
107
126
  token: userDeviceInfoObj.deviceToken,
108
127
  notification: {
@@ -132,22 +151,22 @@ var Event = /** @class */ (function () {
132
151
  }
133
152
  console.log("FCM message payload------>", message);
134
153
  console.log("notificationDataObj inside if condition------>", JSON.stringify(notificationDataObj));
135
- _a.label = 4;
154
+ _c.label = 4;
136
155
  case 4:
137
- _a.trys.push([4, 6, , 7]);
156
+ _c.trys.push([4, 6, , 7]);
138
157
  return [4 /*yield*/, admin.messaging().send(message)];
139
158
  case 5:
140
- response = _a.sent();
159
+ response = _c.sent();
141
160
  console.log('Successfully sent FCM notify(Mobile) message:', response);
142
161
  return [3 /*break*/, 7];
143
162
  case 6:
144
- error_1 = _a.sent();
163
+ error_1 = _c.sent();
145
164
  console.log('ERROR WHILE sent FCM notify(Mobile) message:', error_1.stack);
146
165
  return [3 /*break*/, 7];
147
166
  case 7: return [3 /*break*/, 9];
148
167
  case 8:
149
168
  console.log('Attention!!-- We are not sending mobile notifications due to lack of FIREBASE ADMIN APP configurations.\n Please provide firebaseSet-up.JSON file.');
150
- _a.label = 9;
169
+ _c.label = 9;
151
170
  case 9:
152
171
  // if (userId && data.SocketObj && !data.SocketObj.userId) {
153
172
  //QPC-7064, Ankush changes added
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.371",
3
+ "version": "1.0.373",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {