@optimiser/common 1.0.365 → 1.0.367

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 (69) hide show
  1. package/dist/aws/awsservices.d.ts +39 -39
  2. package/dist/aws/awsservices.js +398 -398
  3. package/dist/constants.d.ts +35 -35
  4. package/dist/constants.js +36 -36
  5. package/dist/enums/databasetype.enum.d.ts +7 -7
  6. package/dist/enums/databasetype.enum.js +11 -11
  7. package/dist/enums/log.enum.d.ts +22 -22
  8. package/dist/enums/log.enum.js +26 -26
  9. package/dist/index.d.ts +25 -25
  10. package/dist/index.js +69 -61
  11. package/dist/lib/activity.d.ts +1 -1
  12. package/dist/lib/activity.js +44 -44
  13. package/dist/lib/calculatedbsize.d.ts +15 -15
  14. package/dist/lib/calculatedbsize.js +75 -75
  15. package/dist/lib/connection.d.ts +116 -116
  16. package/dist/lib/connection.js +595 -595
  17. package/dist/lib/convertfilesize.d.ts +2 -2
  18. package/dist/lib/convertfilesize.js +15 -15
  19. package/dist/lib/countrycode.d.ts +2 -2
  20. package/dist/lib/countrycode.js +255 -255
  21. package/dist/lib/event.d.ts +26 -26
  22. package/dist/lib/event.js +252 -248
  23. package/dist/lib/helper.d.ts +94 -93
  24. package/dist/lib/helper.js +1016 -1009
  25. package/dist/lib/memoryserverclient.d.ts +40 -40
  26. package/dist/lib/memoryserverclient.js +256 -252
  27. package/dist/lib/operautilitycommon.d.ts +65 -65
  28. package/dist/lib/operautilitycommon.js +620 -620
  29. package/dist/lib/redis.d.ts +21 -21
  30. package/dist/lib/redis.js +46 -46
  31. package/dist/lib/socketidfromredis.d.ts +3 -3
  32. package/dist/lib/socketidfromredis.js +5 -5
  33. package/dist/lib/taskutils.d.ts +40 -40
  34. package/dist/lib/taskutils.js +656 -656
  35. package/dist/lib/utility.d.ts +300 -298
  36. package/dist/lib/utility.js +5626 -5621
  37. package/dist/lib/validateRequest.d.ts +3 -3
  38. package/dist/lib/validateRequest.js +13 -13
  39. package/dist/logs/auditlog.d.ts +25 -25
  40. package/dist/logs/auditlog.js +1033 -1029
  41. package/dist/logs/checklogtable.d.ts +3 -3
  42. package/dist/logs/checklogtable.js +67 -67
  43. package/dist/logs/log.table.d.ts +7 -7
  44. package/dist/logs/log.table.js +127 -127
  45. package/dist/modals/connection.modal.d.ts +32 -32
  46. package/dist/modals/connection.modal.js +2 -2
  47. package/dist/modals/globalNotification.modal.d.ts +8 -8
  48. package/dist/modals/globalNotification.modal.js +2 -2
  49. package/dist/modals/log.modal.d.ts +64 -64
  50. package/dist/modals/log.modal.js +2 -2
  51. package/dist/modals/mail.modal.d.ts +6 -6
  52. package/dist/modals/mail.modal.js +2 -2
  53. package/dist/modals/notificationData.modal.d.ts +29 -29
  54. package/dist/modals/notificationData.modal.js +2 -2
  55. package/dist/modals/redisconfig.modal.d.ts +6 -6
  56. package/dist/modals/redisconfig.modal.js +2 -2
  57. package/dist/modals/sqsconfig.modal.d.ts +8 -8
  58. package/dist/modals/sqsconfig.modal.js +2 -2
  59. package/dist/modals/utility.modal.d.ts +17 -17
  60. package/dist/modals/utility.modal.js +2 -2
  61. package/dist/utility/crypto.d.ts +4 -4
  62. package/dist/utility/crypto.js +43 -43
  63. package/dist/utility/errorHandler.d.ts +30 -30
  64. package/dist/utility/errorHandler.js +24 -24
  65. package/dist/utility/errorHandlerForServices.d.ts +22 -22
  66. package/dist/utility/errorHandlerForServices.js +19 -19
  67. package/dist/utility/mail.d.ts +21 -21
  68. package/dist/utility/mail.js +91 -87
  69. package/package.json +3 -3
package/dist/lib/event.js CHANGED
@@ -1,248 +1,252 @@
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
- };
21
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
22
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
23
- return new (P || (P = Promise))(function (resolve, reject) {
24
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
25
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
26
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
27
- step((generator = generator.apply(thisArg, _arguments || [])).next());
28
- });
29
- };
30
- var __generator = (this && this.__generator) || function (thisArg, body) {
31
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
32
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
33
- function verb(n) { return function (v) { return step([n, v]); }; }
34
- function step(op) {
35
- if (f) throw new TypeError("Generator is already executing.");
36
- while (_) try {
37
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
38
- if (y = 0, t) op = [op[0] & 2, t.value];
39
- switch (op[0]) {
40
- case 0: case 1: t = op; break;
41
- case 4: _.label++; return { value: op[1], done: false };
42
- case 5: _.label++; y = op[1]; op = [0]; continue;
43
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
44
- default:
45
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
46
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
47
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
48
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
49
- if (t[2]) _.ops.pop();
50
- _.trys.pop(); continue;
51
- }
52
- op = body.call(thisArg, _);
53
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
54
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
55
- }
56
- };
57
- Object.defineProperty(exports, "__esModule", { value: true });
58
- exports.Event = void 0;
59
- var aws_sdk_1 = require("aws-sdk");
60
- var uuid_1 = require("uuid");
61
- var mongodb_1 = require("mongodb");
62
- var admin = __importStar(require("firebase-admin"));
63
- var Event = /** @class */ (function () {
64
- function Event(eventConfig) {
65
- var _this = this;
66
- /**
67
- * @param userId
68
- * @param db company DB
69
- * @param data Notification Object to send Push Notification, EMail and socket Events
70
- */
71
- this.CreateEvent = function (userId, db, data) { return __awaiter(_this, void 0, void 0, function () {
72
- var _this = this;
73
- return __generator(this, function (_a) {
74
- return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
75
- var notificationDataObj, userObj, userDeviceInfoObj, message, response, error_1, uniqueID, params;
76
- return __generator(this, function (_a) {
77
- switch (_a.label) {
78
- case 0:
79
- if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 8];
80
- notificationDataObj = data.PushNotificationObj;
81
- return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
82
- case 1:
83
- userObj = _a.sent();
84
- if (userObj && userObj.endpoint && userObj.keys && data.PushNotificationObj) {
85
- data.PushNotificationObj["endpoint"] = userObj.endpoint;
86
- data.PushNotificationObj["keys"] = userObj.keys;
87
- }
88
- else {
89
- delete data.PushNotificationObj;
90
- }
91
- if (!this.FCMMobileServiceAccountKey) return [3 /*break*/, 7];
92
- return [4 /*yield*/, db.collection('UserMobileNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
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
- notification: {
104
- sound: 'default' // added by komal Include the default sound for Android
105
- },
106
- priority: 'high' // You can set the priority to 'high' or 'normal' for Android
107
- },
108
- apns: {
109
- payload: {
110
- aps: {
111
- contentAvailable: true,
112
- sound: 'default' // added by komal Include the default sound for iOS
113
- }
114
- }
115
- },
116
- data: notificationDataObj // changes done by komal, to get data attr val in notification
117
- };
118
- _a.label = 3;
119
- case 3:
120
- _a.trys.push([3, 5, , 6]);
121
- return [4 /*yield*/, admin.messaging().send(message)];
122
- case 4:
123
- response = _a.sent();
124
- console.log('Successfully sent FCM notify(Mobile) message:', response);
125
- return [3 /*break*/, 6];
126
- case 5:
127
- error_1 = _a.sent();
128
- console.log('ERROR WHILE sent FCM notify(Mobile) message:', error_1.stack);
129
- return [3 /*break*/, 6];
130
- case 6: return [3 /*break*/, 8];
131
- case 7:
132
- console.log('Attention!!-- We are not sending mobile notifications due to lack of FIREBASE ADMIN APP configurations.\n Please provide firebaseSet-up.JSON file.');
133
- _a.label = 8;
134
- case 8:
135
- // if (userId && data.SocketObj && !data.SocketObj.userId) {
136
- //QPC-7064, Ankush changes added
137
- if (userId && data.SocketObj && data.SocketObj.userId != userId) {
138
- data.SocketObj["userId"] = userId;
139
- }
140
- uniqueID = uuid_1.v4() + "-" + Math.floor(Math.random() * 100000000);
141
- params = {
142
- MessageGroupId: uniqueID,
143
- MessageDeduplicationId: uniqueID,
144
- MessageBody: JSON.stringify(data),
145
- QueueUrl: this.queueURL
146
- };
147
- console.log('Queue enter---->', params);
148
- this.sqs.sendMessage(params, function (err, data) {
149
- if (err) {
150
- reject(err);
151
- console.log('Queue reject---->', err);
152
- }
153
- else {
154
- resolve(data.MessageId);
155
- console.log('Queue resolve---->', data);
156
- }
157
- });
158
- return [2 /*return*/];
159
- }
160
- });
161
- }); })];
162
- });
163
- }); };
164
- /**
165
- * @param userIds
166
- * @param db
167
- * @param data notification object
168
- * @description to send push notification, desktop notification, Email notification to user
169
- */
170
- this.CreateEvents = function (userIds, db, data) { return __awaiter(_this, void 0, void 0, function () {
171
- var promiseArr;
172
- var _this = this;
173
- return __generator(this, function (_a) {
174
- promiseArr = [];
175
- if (userIds && userIds.length > 0 && db) {
176
- userIds.forEach(function (userId) {
177
- promiseArr.push(_this.CreateEvent(userId, db, data));
178
- });
179
- }
180
- return [2 /*return*/, Promise.all(promiseArr)];
181
- });
182
- }); };
183
- this.RefreshNotificationBar = function (userId) {
184
- _this.CreateEvent(userId, null, {
185
- SocketObj: {
186
- eventType: "refresh-notification",
187
- data: "Refresh Notification"
188
- }
189
- });
190
- };
191
- this.SetGlobalNotification = function (data, db) {
192
- return new Promise(function (resolve, reject) {
193
- var saveObj = {
194
- IsActive: true,
195
- CreatedDate: new Date(),
196
- Users: [],
197
- EventObjectName: data.EventObjectName,
198
- EventID: new mongodb_1.ObjectId(data.EventID),
199
- CreatedBy: new mongodb_1.ObjectId(data.CreatedBy),
200
- Message: data.Message
201
- };
202
- var Userid = [];
203
- data.UserIds.forEach(function (id) {
204
- Userid.push({
205
- "IsSeen": false,
206
- "IsNew": true,
207
- "UserID": new mongodb_1.ObjectId(id)
208
- });
209
- });
210
- saveObj.Users = Userid;
211
- db.collection("Notification").insertOne(saveObj, function (error, result) {
212
- if (error) {
213
- reject(error);
214
- }
215
- else {
216
- resolve(result);
217
- data.UserIds.forEach(function (id) {
218
- _this.RefreshNotificationBar(id.toString());
219
- });
220
- }
221
- });
222
- });
223
- };
224
- this.queueURL = eventConfig.QUEUE_URL;
225
- this.sqs = new aws_sdk_1.SQS({
226
- apiVersion: eventConfig.SQS_API_VERSION,
227
- region: eventConfig.SQS_REGION,
228
- accessKeyId: eventConfig.SQS_ACCESSKEY_ID,
229
- secretAccessKey: eventConfig.SQS_SECRET_KEY
230
- });
231
- this.FCMMobileServiceAccountKey = eventConfig === null || eventConfig === void 0 ? void 0 : eventConfig.FCM_NOTIFICATION_SERVICE_ACCOUNT_KEY;
232
- if (eventConfig === null || eventConfig === void 0 ? void 0 : eventConfig.FCM_NOTIFICATION_SERVICE_ACCOUNT_KEY) { // scope added by komal, to handle the firebase warning,
233
- try {
234
- admin.initializeApp({
235
- credential: admin.credential.cert(this.FCMMobileServiceAccountKey)
236
- });
237
- }
238
- catch (error) {
239
- console.log('Error while INITIALIZING FIREBASE ADMIN APP\n Please check firebaseSet-up.JSON file.\n This will impact mobile app notifications -----', error);
240
- }
241
- }
242
- else {
243
- console.log('We are not INITIALIZING mobile notifications due to lack of FIREBASE ADMIN APP configurations.\n Please provide firebaseSet-up.JSON file.');
244
- }
245
- }
246
- return Event;
247
- }());
248
- exports.Event = Event;
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
26
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
27
+ return new (P || (P = Promise))(function (resolve, reject) {
28
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
29
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
30
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
31
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
32
+ });
33
+ };
34
+ var __generator = (this && this.__generator) || function (thisArg, body) {
35
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
36
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
37
+ function verb(n) { return function (v) { return step([n, v]); }; }
38
+ function step(op) {
39
+ if (f) throw new TypeError("Generator is already executing.");
40
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
41
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
42
+ if (y = 0, t) op = [op[0] & 2, t.value];
43
+ switch (op[0]) {
44
+ case 0: case 1: t = op; break;
45
+ case 4: _.label++; return { value: op[1], done: false };
46
+ case 5: _.label++; y = op[1]; op = [0]; continue;
47
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
48
+ default:
49
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
50
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
51
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
52
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
53
+ if (t[2]) _.ops.pop();
54
+ _.trys.pop(); continue;
55
+ }
56
+ op = body.call(thisArg, _);
57
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
58
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
59
+ }
60
+ };
61
+ Object.defineProperty(exports, "__esModule", { value: true });
62
+ exports.Event = void 0;
63
+ var aws_sdk_1 = require("aws-sdk");
64
+ var uuid_1 = require("uuid");
65
+ var mongodb_1 = require("mongodb");
66
+ var admin = __importStar(require("firebase-admin"));
67
+ var Event = /** @class */ (function () {
68
+ function Event(eventConfig) {
69
+ var _this = this;
70
+ /**
71
+ * @param userId
72
+ * @param db company DB
73
+ * @param data Notification Object to send Push Notification, EMail and socket Events
74
+ */
75
+ this.CreateEvent = function (userId, db, data) { return __awaiter(_this, void 0, void 0, function () {
76
+ var _this = this;
77
+ return __generator(this, function (_a) {
78
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(_this, void 0, void 0, function () {
79
+ var notificationDataObj, userObj, userDeviceInfoObj, message, response, error_1, uniqueID, params;
80
+ return __generator(this, function (_a) {
81
+ switch (_a.label) {
82
+ case 0:
83
+ if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 8];
84
+ notificationDataObj = data.PushNotificationObj;
85
+ return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
86
+ case 1:
87
+ userObj = _a.sent();
88
+ if (userObj && userObj.endpoint && userObj.keys && data.PushNotificationObj) {
89
+ data.PushNotificationObj["endpoint"] = userObj.endpoint;
90
+ data.PushNotificationObj["keys"] = userObj.keys;
91
+ }
92
+ else {
93
+ delete data.PushNotificationObj;
94
+ }
95
+ if (!this.FCMMobileServiceAccountKey) return [3 /*break*/, 7];
96
+ return [4 /*yield*/, db.collection('UserMobileNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
97
+ case 2:
98
+ userDeviceInfoObj = _a.sent();
99
+ if (!(userDeviceInfoObj && userDeviceInfoObj.deviceToken && notificationDataObj)) return [3 /*break*/, 6];
100
+ message = {
101
+ token: userDeviceInfoObj.deviceToken,
102
+ notification: {
103
+ title: notificationDataObj.title,
104
+ body: notificationDataObj.message
105
+ },
106
+ android: {
107
+ notification: {
108
+ sound: 'default' // added by komal Include the default sound for Android
109
+ },
110
+ priority: 'high' // You can set the priority to 'high' or 'normal' for Android
111
+ },
112
+ apns: {
113
+ payload: {
114
+ aps: {
115
+ contentAvailable: true,
116
+ sound: 'default' // added by komal Include the default sound for iOS
117
+ }
118
+ }
119
+ },
120
+ data: notificationDataObj // changes done by komal, to get data attr val in notification
121
+ };
122
+ _a.label = 3;
123
+ case 3:
124
+ _a.trys.push([3, 5, , 6]);
125
+ return [4 /*yield*/, admin.messaging().send(message)];
126
+ case 4:
127
+ response = _a.sent();
128
+ console.log('Successfully sent FCM notify(Mobile) message:', response);
129
+ return [3 /*break*/, 6];
130
+ case 5:
131
+ error_1 = _a.sent();
132
+ console.log('ERROR WHILE sent FCM notify(Mobile) message:', error_1.stack);
133
+ return [3 /*break*/, 6];
134
+ case 6: return [3 /*break*/, 8];
135
+ case 7:
136
+ console.log('Attention!!-- We are not sending mobile notifications due to lack of FIREBASE ADMIN APP configurations.\n Please provide firebaseSet-up.JSON file.');
137
+ _a.label = 8;
138
+ case 8:
139
+ // if (userId && data.SocketObj && !data.SocketObj.userId) {
140
+ //QPC-7064, Ankush changes added
141
+ if (userId && data.SocketObj && data.SocketObj.userId != userId) {
142
+ data.SocketObj["userId"] = userId;
143
+ }
144
+ uniqueID = "".concat((0, uuid_1.v4)(), "-").concat(Math.floor(Math.random() * 100000000));
145
+ params = {
146
+ MessageGroupId: uniqueID,
147
+ MessageDeduplicationId: uniqueID,
148
+ MessageBody: JSON.stringify(data),
149
+ QueueUrl: this.queueURL
150
+ };
151
+ console.log('Queue enter---->', params);
152
+ this.sqs.sendMessage(params, function (err, data) {
153
+ if (err) {
154
+ reject(err);
155
+ console.log('Queue reject---->', err);
156
+ }
157
+ else {
158
+ resolve(data.MessageId);
159
+ console.log('Queue resolve---->', data);
160
+ }
161
+ });
162
+ return [2 /*return*/];
163
+ }
164
+ });
165
+ }); })];
166
+ });
167
+ }); };
168
+ /**
169
+ * @param userIds
170
+ * @param db
171
+ * @param data notification object
172
+ * @description to send push notification, desktop notification, Email notification to user
173
+ */
174
+ this.CreateEvents = function (userIds, db, data) { return __awaiter(_this, void 0, void 0, function () {
175
+ var promiseArr;
176
+ var _this = this;
177
+ return __generator(this, function (_a) {
178
+ promiseArr = [];
179
+ if (userIds && userIds.length > 0 && db) {
180
+ userIds.forEach(function (userId) {
181
+ promiseArr.push(_this.CreateEvent(userId, db, data));
182
+ });
183
+ }
184
+ return [2 /*return*/, Promise.all(promiseArr)];
185
+ });
186
+ }); };
187
+ this.RefreshNotificationBar = function (userId) {
188
+ _this.CreateEvent(userId, null, {
189
+ SocketObj: {
190
+ eventType: "refresh-notification",
191
+ data: "Refresh Notification"
192
+ }
193
+ });
194
+ };
195
+ this.SetGlobalNotification = function (data, db) {
196
+ return new Promise(function (resolve, reject) {
197
+ var saveObj = {
198
+ IsActive: true,
199
+ CreatedDate: new Date(),
200
+ Users: [],
201
+ EventObjectName: data.EventObjectName,
202
+ EventID: new mongodb_1.ObjectId(data.EventID),
203
+ CreatedBy: new mongodb_1.ObjectId(data.CreatedBy),
204
+ Message: data.Message
205
+ };
206
+ var Userid = [];
207
+ data.UserIds.forEach(function (id) {
208
+ Userid.push({
209
+ "IsSeen": false,
210
+ "IsNew": true,
211
+ "UserID": new mongodb_1.ObjectId(id)
212
+ });
213
+ });
214
+ saveObj.Users = Userid;
215
+ db.collection("Notification").insertOne(saveObj, function (error, result) {
216
+ if (error) {
217
+ reject(error);
218
+ }
219
+ else {
220
+ resolve(result);
221
+ data.UserIds.forEach(function (id) {
222
+ _this.RefreshNotificationBar(id.toString());
223
+ });
224
+ }
225
+ });
226
+ });
227
+ };
228
+ this.queueURL = eventConfig.QUEUE_URL;
229
+ this.sqs = new aws_sdk_1.SQS({
230
+ apiVersion: eventConfig.SQS_API_VERSION,
231
+ region: eventConfig.SQS_REGION,
232
+ accessKeyId: eventConfig.SQS_ACCESSKEY_ID,
233
+ secretAccessKey: eventConfig.SQS_SECRET_KEY
234
+ });
235
+ this.FCMMobileServiceAccountKey = eventConfig === null || eventConfig === void 0 ? void 0 : eventConfig.FCM_NOTIFICATION_SERVICE_ACCOUNT_KEY;
236
+ if (eventConfig === null || eventConfig === void 0 ? void 0 : eventConfig.FCM_NOTIFICATION_SERVICE_ACCOUNT_KEY) { // scope added by komal, to handle the firebase warning,
237
+ try {
238
+ admin.initializeApp({
239
+ credential: admin.credential.cert(this.FCMMobileServiceAccountKey)
240
+ });
241
+ }
242
+ catch (error) {
243
+ console.log('Error while INITIALIZING FIREBASE ADMIN APP\n Please check firebaseSet-up.JSON file.\n This will impact mobile app notifications -----', error);
244
+ }
245
+ }
246
+ else {
247
+ console.log('We are not INITIALIZING mobile notifications due to lack of FIREBASE ADMIN APP configurations.\n Please provide firebaseSet-up.JSON file.');
248
+ }
249
+ }
250
+ return Event;
251
+ }());
252
+ exports.Event = Event;