@optimiser/common 1.0.355 → 1.0.357

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.
@@ -6,6 +6,7 @@ import { GlobalNotificationData } from "../modals/globalNotification.modal";
6
6
  export declare class Event {
7
7
  private sqs;
8
8
  private queueURL;
9
+ private FCMMobileServiceAccountKey;
9
10
  constructor(eventConfig: SQSConfig);
10
11
  /**
11
12
  * @param userId
package/dist/lib/event.js CHANGED
@@ -1,4 +1,23 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
5
+ }) : (function(o, m, k, k2) {
6
+ if (k2 === undefined) k2 = k;
7
+ o[k2] = m[k];
8
+ }));
9
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
10
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
11
+ }) : function(o, v) {
12
+ o["default"] = v;
13
+ });
14
+ var __importStar = (this && this.__importStar) || function (mod) {
15
+ if (mod && mod.__esModule) return mod;
16
+ var result = {};
17
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
18
+ __setModuleDefault(result, mod);
19
+ return result;
20
+ };
2
21
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
22
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
23
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -40,6 +59,7 @@ exports.Event = void 0;
40
59
  var aws_sdk_1 = require("aws-sdk");
41
60
  var uuid_1 = require("uuid");
42
61
  var mongodb_1 = require("mongodb");
62
+ var admin = __importStar(require("firebase-admin"));
43
63
  var Event = /** @class */ (function () {
44
64
  function Event(eventConfig) {
45
65
  var _this = this;
@@ -52,11 +72,12 @@ var Event = /** @class */ (function () {
52
72
  var _this = this;
53
73
  return __generator(this, function (_a) {
54
74
  return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
55
- var userObj, uniqueID, params;
75
+ var notificationDataObj, userObj, userDeviceInfoObj, message, response, error_1, uniqueID, params;
56
76
  return __generator(this, function (_a) {
57
77
  switch (_a.label) {
58
78
  case 0:
59
- if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 2];
79
+ if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 8];
80
+ notificationDataObj = data.PushNotificationObj;
60
81
  return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
61
82
  case 1:
62
83
  userObj = _a.sent();
@@ -67,8 +88,49 @@ var Event = /** @class */ (function () {
67
88
  else {
68
89
  delete data.PushNotificationObj;
69
90
  }
70
- _a.label = 2;
91
+ if (!this.FCMMobileServiceAccountKey) return [3 /*break*/, 7];
92
+ return [4 /*yield*/, db.collection('UserMobileNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
71
93
  case 2:
94
+ userDeviceInfoObj = _a.sent();
95
+ if (!(userDeviceInfoObj && userDeviceInfoObj.deviceToken && notificationDataObj)) return [3 /*break*/, 6];
96
+ message = {
97
+ token: userDeviceInfoObj.deviceToken,
98
+ notification: {
99
+ title: notificationDataObj.title,
100
+ body: notificationDataObj.message
101
+ },
102
+ android: {
103
+ priority: 'high' // You can set the priority to 'high' or 'normal' for Android
104
+ },
105
+ apns: {
106
+ payload: {
107
+ aps: {
108
+ contentAvailable: true // For iOS, setting contentAvailable to true makes the message a silent notification
109
+ }
110
+ }
111
+ },
112
+ data: {
113
+ title: notificationDataObj.title,
114
+ body: notificationDataObj.message
115
+ }
116
+ };
117
+ _a.label = 3;
118
+ case 3:
119
+ _a.trys.push([3, 5, , 6]);
120
+ return [4 /*yield*/, admin.messaging().send(message)];
121
+ case 4:
122
+ response = _a.sent();
123
+ console.log('Successfully sent FCM notify(Mobile) message:', response);
124
+ return [3 /*break*/, 6];
125
+ case 5:
126
+ error_1 = _a.sent();
127
+ console.log('ERROR WHILE sent FCM notify(Mobile) message:', error_1.stack);
128
+ return [3 /*break*/, 6];
129
+ case 6: return [3 /*break*/, 8];
130
+ case 7:
131
+ console.log('Not able to INITIALISE THE FIREBASE ADMIN APP--');
132
+ _a.label = 8;
133
+ case 8:
72
134
  // if (userId && data.SocketObj && !data.SocketObj.userId) {
73
135
  //QPC-7064, Ankush changes added
74
136
  if (userId && data.SocketObj && data.SocketObj.userId != userId) {
@@ -165,6 +227,15 @@ var Event = /** @class */ (function () {
165
227
  accessKeyId: eventConfig.SQS_ACCESSKEY_ID,
166
228
  secretAccessKey: eventConfig.SQS_SECRET_KEY
167
229
  });
230
+ this.FCMMobileServiceAccountKey = eventConfig.FCM_NOTIFICATION_SERVICE_ACCOUNT_KEY;
231
+ try {
232
+ admin.initializeApp({
233
+ credential: admin.credential.cert(this.FCMMobileServiceAccountKey)
234
+ });
235
+ }
236
+ catch (error) {
237
+ console.log('Error while INITIALIZING FIREBASE ADMIN APP\n Please check service-accountKey.JSON file.\n This will impact mobile app notifications -----', error);
238
+ }
168
239
  }
169
240
  return Event;
170
241
  }());
@@ -5524,26 +5524,28 @@ exports.GetFileFolderDetailsInFolderForDriveSharing = GetFileFolderDetailsInFold
5524
5524
  */
5525
5525
  function SyncTotalSlotRemaining(registrationID, db) {
5526
5526
  return __awaiter(this, void 0, void 0, function () {
5527
- var registrationData, totalDelegates, maximumRegistration, eventSchema, regDelegates_1, includeGuestInRegCount, registeredDelegates, remainingSlots;
5527
+ var eventSchema, registrationData, totalDelegates, maximumRegistration, regDelegates_1, includeGuestInRegCount, registeredDelegates, remainingSlots;
5528
5528
  return __generator(this, function (_a) {
5529
5529
  switch (_a.label) {
5530
5530
  case 0:
5531
5531
  if (!registrationID) return [3 /*break*/, 7];
5532
- return [4 /*yield*/, db.collection('EventRegistration').findOne({ '_id': registrationID, 'IsActive': true })];
5532
+ return [4 /*yield*/, db.collection('ObjectSchema').findOne({ Name: "EventRegistration" })];
5533
5533
  case 1:
5534
+ eventSchema = _a.sent();
5535
+ if (!(eventSchema.TotalSlotSyncingIn != 'Custom')) return [3 /*break*/, 7];
5536
+ return [4 /*yield*/, db.collection('EventRegistration').findOne({ '_id': registrationID, 'IsActive': true })];
5537
+ case 2:
5534
5538
  registrationData = _a.sent();
5535
5539
  if (!registrationData) return [3 /*break*/, 7];
5536
5540
  totalDelegates = 0;
5537
5541
  maximumRegistration = registrationData.MaximumRegistration;
5538
- if (!(maximumRegistration == undefined)) return [3 /*break*/, 3];
5542
+ if (!(maximumRegistration == undefined)) return [3 /*break*/, 4];
5539
5543
  return [4 /*yield*/, db.collection('EventRegistration').updateOne({ '_id': registrationID, 'IsActive': true }, { $set: { 'TotalSlotRemaining': null } })];
5540
- case 2:
5544
+ case 3:
5541
5545
  _a.sent();
5542
5546
  return [3 /*break*/, 7];
5543
- case 3: return [4 /*yield*/, db.collection('ObjectSchema').findOne({ Name: "EventRegistration" })];
5544
5547
  case 4:
5545
- eventSchema = _a.sent();
5546
- regDelegates_1 = (eventSchema === null || eventSchema === void 0 ? void 0 : eventSchema.RegisteredDelegates) || [];
5548
+ regDelegates_1 = eventSchema.RegisteredDelegates || [];
5547
5549
  includeGuestInRegCount = registrationData.IncludeGuestInRegCount;
5548
5550
  return [4 /*yield*/, db.collection('EventDelegate').find({ 'EventID': registrationData.EventID, 'RegistrationType': registrationID, 'IsActive': true }).toArray()];
5549
5551
  case 5:
@@ -4,4 +4,5 @@ export interface SQSConfig {
4
4
  SQS_REGION: string;
5
5
  SQS_ACCESSKEY_ID: string;
6
6
  SQS_SECRET_KEY: string;
7
+ FCM_NOTIFICATION_SERVICE_ACCOUNT_KEY: string;
7
8
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.355",
3
+ "version": "1.0.357",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -25,6 +25,7 @@
25
25
  "exceljs": "^4.3.0",
26
26
  "express": "^4.17.1",
27
27
  "express-validator": "^6.9.2",
28
+ "firebase-admin": "^12.0.0",
28
29
  "geoip-lite": "^1.4.2",
29
30
  "google-libphonenumber": "^3.2.30",
30
31
  "ioredis": "^4.17.3",