@optimiser/common 1.0.243 → 1.0.247

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.
@@ -1,9 +1,47 @@
1
1
  "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
13
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (_) try {
18
+ 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;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
2
38
  var __importDefault = (this && this.__importDefault) || function (mod) {
3
39
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
40
  };
5
41
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.OperaErrorHandler = exports.SyncContactWithOperaOnEmailUnsubscribe = exports.GetIntegrationSettings = void 0;
42
+ exports.EmailPrioritySearch = exports.AddToQueueForOpera = exports.UpdateInitialSyncData = exports.GetProfileDetailByDynamicFields = exports.OperaErrorHandler = exports.SyncContactWithOperaOnEmailUnsubscribe = exports.GetIntegrationSettings = void 0;
43
+ var mongodb_1 = require("mongodb");
44
+ var __1 = require("..");
7
45
  var constants_1 = __importDefault(require("../constants"));
8
46
  var GetIntegrationSettings = function (db, hotelCode) {
9
47
  return new Promise(function (resolve, reject) {
@@ -106,3 +144,476 @@ var OperaErrorHandler = function (db, ex) {
106
144
  });
107
145
  };
108
146
  exports.OperaErrorHandler = OperaErrorHandler;
147
+ /**
148
+ * This function is used to search profiles by dynamics fields in both Memory server and db.
149
+ * If data found in memory server then it search data by _id in db the return data.
150
+ *
151
+ * @param params.ModuleName Name of Module either Account | Contact.
152
+ * @param params.MappingFields fields which is used for searching
153
+ * @param params.ModuleData Data of fields
154
+ * @param params.db database objects
155
+ * @param params.MongodbTransactionQueryOptions Mongodb query option, it may have transaction as well.
156
+ * @param params.SelectedFields to get only selected fields
157
+ * @param params.AllowInactive to search data without IsActive field.
158
+ * @param params.SearchFromMemoryServer to indicate searcing is to do from memory server
159
+ * @param params.MemoryServerClient memory server client object to get data from memory server
160
+ * @param params.CompanyId to indicate searcing is to do from memory server
161
+ * @param params.DataSet to indicate searcing is to do from memory server
162
+ *
163
+ * @returns [error,ResultData]
164
+ */
165
+ var GetProfileDetailByDynamicFields = function (params) {
166
+ return __awaiter(this, void 0, void 0, function () {
167
+ var mongodbTransactionQueryopts, searchObj, searchItems, len, i, field, appendSearch, _a, memoryServerSearchError, dataResult, projection, i, resultData, ex_1, searchObj, projection, len, i, field, i, resultData, ex_2;
168
+ return __generator(this, function (_b) {
169
+ switch (_b.label) {
170
+ case 0:
171
+ mongodbTransactionQueryopts = {};
172
+ //if query options passed then setting them to pass into query.
173
+ if (params.MongodbTransactionQueryOptions) {
174
+ mongodbTransactionQueryopts = params.MongodbTransactionQueryOptions;
175
+ }
176
+ if (!params.SearchFromMemoryServer) return [3 /*break*/, 10];
177
+ searchObj = "x=>";
178
+ searchItems = new Array();
179
+ /*Preparing searching object for memory server*/
180
+ for (len = params.MappingFields.length, i = 0; i < len; i++) {
181
+ field = params.MappingFields[i];
182
+ appendSearch = "";
183
+ switch (field.UIDataType) {
184
+ case 'email':
185
+ case 'text':
186
+ //left hand part
187
+ appendSearch += "x." + field.Name + " && x." + field.Name + ".toString().toLowerCase().trim()";
188
+ //right hand part
189
+ appendSearch += " === ('" + params.ModuleData[field.Name] + "').toString().toLowerCase().trim()";
190
+ break;
191
+ // case 'multilookup':
192
+ // break;
193
+ // case 'multiselect':
194
+ // break;
195
+ case 'lookup':
196
+ case 'objectid':
197
+ //left hand part
198
+ appendSearch += "x." + field.Name + " && x." + field.Name + ".toString()";
199
+ //right hand part
200
+ appendSearch += " === ('" + params.ModuleData[field.Name] + "').toString()";
201
+ break;
202
+ case 'phone':
203
+ //left hand part
204
+ appendSearch += "x." + field.Name + " && x." + field.Name + ".toString().toLowerCase().trim()";
205
+ //right hand part
206
+ appendSearch += " === ('" + params.ModuleData[field.Name] + "').toString().toLowerCase().trim()";
207
+ break;
208
+ case 'dropdown':
209
+ appendSearch += "x." + field.Name + " && x." + field.Name + ".toString()";
210
+ //right hand part
211
+ appendSearch += " === ('" + params.ModuleData[field.Name] + "').toString()";
212
+ break;
213
+ default:
214
+ appendSearch += "x." + field.Name + " && x." + field.Name + ".toString()";
215
+ //right hand part
216
+ appendSearch += " === ('" + params.ModuleData[field.Name] + "').toString()";
217
+ break;
218
+ }
219
+ if (appendSearch && appendSearch.length > 0) {
220
+ searchItems.push(appendSearch);
221
+ }
222
+ }
223
+ if (!(searchItems.length > 0)) return [3 /*break*/, 8];
224
+ searchObj += searchItems.join(' && ');
225
+ //if search required on InActive data
226
+ // if (params.AllowInactive != true) {
227
+ // searchObj += " && x.IsActive== true";
228
+ // }
229
+ console.log("Search query===>", searchObj);
230
+ return [4 /*yield*/, params.MemoryServerClient.Fetch('search', { 'CompanyID': params.CompanyId, 'DataSet': params.DataSet, 'findQuery': searchObj })];
231
+ case 1:
232
+ _a = _b.sent(), memoryServerSearchError = _a[0], dataResult = _a[1];
233
+ if (!(dataResult && dataResult.response && dataResult.response._id)) return [3 /*break*/, 6];
234
+ projection = {};
235
+ //to get only required field otherwise get all data of object by id
236
+ if (params.SelectedFields && params.SelectedFields.length > 0) {
237
+ for (i = 0; i < params.SelectedFields.length; i++) {
238
+ projection[params.SelectedFields[i]] = 1;
239
+ }
240
+ }
241
+ else {
242
+ projection = {};
243
+ }
244
+ resultData = null;
245
+ _b.label = 2;
246
+ case 2:
247
+ _b.trys.push([2, 4, , 5]);
248
+ return [4 /*yield*/, params.db.collection(params.ModuleName).findOne({ _id: new mongodb_1.ObjectId(dataResult.response._id) }, projection, mongodbTransactionQueryopts)];
249
+ case 3:
250
+ resultData = _b.sent();
251
+ return [2 /*return*/, [null, resultData]];
252
+ case 4:
253
+ ex_1 = _b.sent();
254
+ return [2 /*return*/, [ex_1, null]];
255
+ case 5: return [3 /*break*/, 7];
256
+ case 6:
257
+ if (memoryServerSearchError) {
258
+ console.log("Error while searching in memory server", memoryServerSearchError);
259
+ return [2 /*return*/, [memoryServerSearchError, null]];
260
+ }
261
+ else {
262
+ console.log("data not found in memory server");
263
+ return [2 /*return*/, [null, null]];
264
+ }
265
+ _b.label = 7;
266
+ case 7: return [3 /*break*/, 9];
267
+ case 8:
268
+ console.log("Search object not prepared");
269
+ return [2 /*return*/, [null, null]];
270
+ case 9: return [3 /*break*/, 14];
271
+ case 10:
272
+ searchObj = {};
273
+ projection = {};
274
+ /*Preparing searching object*/
275
+ for (len = params.MappingFields.length, i = 0; i < len; i++) {
276
+ field = params.MappingFields[i];
277
+ switch (field.UIDataType) {
278
+ case 'email':
279
+ case 'text':
280
+ searchObj[field.Name] = new RegExp('^' + params.ModuleData[field.Name] + '$', 'i');
281
+ break;
282
+ // case 'multilookup':
283
+ // break;
284
+ // case 'multiselect':
285
+ // break;
286
+ case 'lookup':
287
+ case 'objectid':
288
+ searchObj[field.Name] = params.ModuleData[field.Name];
289
+ break;
290
+ case 'phone':
291
+ case 'dropdown':
292
+ searchObj[field.Name] = params.ModuleData[field.Name];
293
+ break;
294
+ default:
295
+ searchObj[field.Name] = params.ModuleData[field.Name];
296
+ break;
297
+ }
298
+ }
299
+ //If serch object build adding IsActive flag
300
+ if (!__1._utility.isEmptyObj(searchObj)) {
301
+ //if search required on InActive data
302
+ if (params.AllowInactive != true) {
303
+ searchObj["IsActive"] = true;
304
+ //to show data is InActive so adding IsActive field in SelectedFields array if not available.
305
+ if (params.SelectedFields && params.SelectedFields.length > 0 && !params.SelectedFields.find(function (x) { return x.Name == "IsActive"; })) {
306
+ params.SelectedFields.push("IsActive");
307
+ }
308
+ }
309
+ }
310
+ else {
311
+ console.log("Search object not prepared");
312
+ return [2 /*return*/, [null, null]];
313
+ }
314
+ //to get only required field otherwise get all data of object by id
315
+ if (params.SelectedFields && params.SelectedFields.length > 0) {
316
+ for (i = 0; i < params.SelectedFields.length; i++) {
317
+ projection[params.SelectedFields[i]] = 1;
318
+ }
319
+ }
320
+ else {
321
+ projection = {};
322
+ }
323
+ resultData = null;
324
+ _b.label = 11;
325
+ case 11:
326
+ _b.trys.push([11, 13, , 14]);
327
+ return [4 /*yield*/, params.db.collection(params.ModuleName).findOne(searchObj, projection, mongodbTransactionQueryopts)];
328
+ case 12:
329
+ resultData = _b.sent();
330
+ return [2 /*return*/, [null, resultData]];
331
+ case 13:
332
+ ex_2 = _b.sent();
333
+ return [2 /*return*/, [ex_2, null]];
334
+ case 14: return [2 /*return*/];
335
+ }
336
+ });
337
+ });
338
+ };
339
+ exports.GetProfileDetailByDynamicFields = GetProfileDetailByDynamicFields;
340
+ /**
341
+ * This function is used to update data.
342
+ * @param params.ModuleName Name of Module either Account | Contact.
343
+ * @param params.Collection Name of Collection
344
+ * @param params.Id which doucment has to update
345
+ * @param params.db database objects
346
+ * @param params.MongodbTransactionQueryOptions Mongodb query option object , it may have transaction as well.
347
+ * @param params.UpdateObj to update data in collection.
348
+
349
+ * @returns
350
+ */
351
+ var UpdateInitialSyncData = function (params) { return __awaiter(void 0, void 0, void 0, function () {
352
+ var mongodbQueryOpts;
353
+ return __generator(this, function (_a) {
354
+ mongodbQueryOpts = {};
355
+ if (params.MongodbQueryOpts) {
356
+ mongodbQueryOpts = params.MongodbQueryOpts;
357
+ }
358
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
359
+ var updatedData, error_1;
360
+ return __generator(this, function (_a) {
361
+ switch (_a.label) {
362
+ case 0:
363
+ _a.trys.push([0, 3, , 4]);
364
+ if (!params) return [3 /*break*/, 2];
365
+ updatedData = null;
366
+ return [4 /*yield*/, params.db.collection(params.Collection).update({ '_id': params.Id }, { $set: params.UpdateObj }, mongodbQueryOpts)];
367
+ case 1:
368
+ updatedData = _a.sent();
369
+ if (updatedData) {
370
+ resolve([null, true]);
371
+ }
372
+ _a.label = 2;
373
+ case 2: return [3 /*break*/, 4];
374
+ case 3:
375
+ error_1 = _a.sent();
376
+ resolve([error_1, null]);
377
+ return [3 /*break*/, 4];
378
+ case 4: return [2 /*return*/];
379
+ }
380
+ });
381
+ }); })];
382
+ });
383
+ }); };
384
+ exports.UpdateInitialSyncData = UpdateInitialSyncData;
385
+ /**
386
+ * This function is used to stop unnecessary databse hits for checking any data available send to opera.
387
+ * this flag will be in reddis
388
+ * @param params.RedisClient reddis client
389
+ * @param params.CompanyId to create/check opera key with company id
390
+ * @param params.Mode GET/SET operation to perform on reddis
391
+ * @param params.db database objects
392
+ * @param params.isAvailable value to set in reddis
393
+
394
+ * @returns
395
+ */
396
+ var AddToQueueForOpera = function (params) { return __awaiter(void 0, void 0, void 0, function () {
397
+ var key, redisDataOnKey, setDataOnKey, setDataOnKey, status_1, setDataOnKey, error_2;
398
+ return __generator(this, function (_a) {
399
+ switch (_a.label) {
400
+ case 0:
401
+ _a.trys.push([0, 14, , 15]);
402
+ key = 'opera-queue:' + params.CompanyId.toString();
403
+ if (!(params.Mode === 'GET')) return [3 /*break*/, 5];
404
+ return [4 /*yield*/, params.RedisClient.hget(key, 'DataAvailable')];
405
+ case 1:
406
+ redisDataOnKey = _a.sent();
407
+ if (!(redisDataOnKey === null || redisDataOnKey === undefined)) return [3 /*break*/, 3];
408
+ return [4 /*yield*/, params.RedisClient.hset(key, { "DataAvailable": params.isAvailable })];
409
+ case 2:
410
+ setDataOnKey = _a.sent();
411
+ // reddis returns 1 when data inserted
412
+ if (setDataOnKey === 1) {
413
+ return [2 /*return*/, [null, 'true']];
414
+ }
415
+ return [3 /*break*/, 4];
416
+ case 3: return [2 /*return*/, [null, redisDataOnKey]];
417
+ case 4: return [3 /*break*/, 13];
418
+ case 5:
419
+ if (!(params.Mode === 'SET')) return [3 /*break*/, 13];
420
+ //
421
+ console.log("Request receive to set in Opera Queue : ", params.isAvailable);
422
+ if (!(params.isAvailable === true)) return [3 /*break*/, 7];
423
+ return [4 /*yield*/, params.RedisClient.hset(key, { "DataAvailable": params.isAvailable })];
424
+ case 6:
425
+ setDataOnKey = _a.sent();
426
+ // reddis returns 1 when data inserted and 0 when data already exists
427
+ if (setDataOnKey === 1 || setDataOnKey === 0) {
428
+ return [2 /*return*/, [null, 'true']];
429
+ }
430
+ return [3 /*break*/, 13];
431
+ case 7:
432
+ if (!(params.isAvailable === false)) return [3 /*break*/, 13];
433
+ console.log("Checking data available or not in OperaApiLogs");
434
+ return [4 /*yield*/, params.db.collection("OperaApiLogs").findOne({ 'Status': { $in: ["-1", "2", "3"] } })];
435
+ case 8:
436
+ status_1 = _a.sent();
437
+ if (!!status_1) return [3 /*break*/, 10];
438
+ console.log("Checking data available or not in OperaDataSyncRequest");
439
+ return [4 /*yield*/, params.db.collection("OperaDataSyncRequest").findOne({ 'Status': '1', 'IsActive': true })];
440
+ case 9:
441
+ status_1 = _a.sent();
442
+ _a.label = 10;
443
+ case 10:
444
+ if (!(status_1 === null || status_1 === undefined)) return [3 /*break*/, 12];
445
+ console.log("Setting Opera Queue as data not available");
446
+ return [4 /*yield*/, params.RedisClient.hset(key, { "DataAvailable": params.isAvailable })];
447
+ case 11:
448
+ setDataOnKey = _a.sent();
449
+ if (setDataOnKey === 1 || setDataOnKey === 0) {
450
+ return [2 /*return*/, [null, 'success']];
451
+ }
452
+ return [3 /*break*/, 13];
453
+ case 12:
454
+ console.log("Data available in queue");
455
+ _a.label = 13;
456
+ case 13: return [3 /*break*/, 15];
457
+ case 14:
458
+ error_2 = _a.sent();
459
+ console.error(error_2);
460
+ return [2 /*return*/, [error_2, null]];
461
+ case 15: return [2 /*return*/];
462
+ }
463
+ });
464
+ }); };
465
+ exports.AddToQueueForOpera = AddToQueueForOpera;
466
+ // email prioritysearch
467
+ /**
468
+ * This function is used to search data in case of contact from memory server using email
469
+ * @param params.db database objects
470
+ * @param params.ProfileType profile type account/contact
471
+ * @param params.PrimaryEmail primary email
472
+ * @param params.SecondaryEmail secondary email
473
+ * @param params.MongodbTransactionQueryOptions Mongodb query option, it may have transaction as well.
474
+ * @param params.SelectedFields to get only selected fields
475
+ * @param params.SearchFromMemoryServer to indicate searcing is to do from memory server
476
+ * @param params.MemoryServerClient memory server client object to get data from memory server
477
+ * @param params.CompanyId to indicate searcing is to do from memory server
478
+ * @param params.DataSet to indicate searcing is to do from memory server
479
+ *
480
+ * @returns
481
+ */
482
+ var EmailPrioritySearch = function (params) { return __awaiter(void 0, void 0, void 0, function () {
483
+ return __generator(this, function (_a) {
484
+ return [2 /*return*/, new Promise(function (resolve, reject) { return __awaiter(void 0, void 0, void 0, function () {
485
+ var $project, i, script, primaryEmail, secondaryEmail, primaryEmail_1, mongodbTransactionQueryopts, _a, memoryServerSearchError, memoryServerSearchData, id, convertedToObjectID, result, mongodbTransactionQueryopts, allContactData, objectID, type, result, primaryEmail_2, secondaryEmail_1, primaryEmailrResult, secondaryEmailResult, result_1, ex_3;
486
+ var _b;
487
+ return __generator(this, function (_c) {
488
+ switch (_c.label) {
489
+ case 0:
490
+ _c.trys.push([0, 11, , 12]);
491
+ $project = {};
492
+ if (params.SelectedFields && params.SelectedFields.length > 0) {
493
+ for (i = 0; i < params.SelectedFields.length; i++) {
494
+ $project[params.SelectedFields[i]] = 1;
495
+ }
496
+ }
497
+ else {
498
+ //setting dummy field in projection for fast query processing
499
+ $project = {};
500
+ }
501
+ if (!(params && params.SearchFromMemoryServer === true)) return [3 /*break*/, 6];
502
+ script = "";
503
+ primaryEmail = null;
504
+ secondaryEmail = null;
505
+ if (params.PrimaryEmail && params.SecondaryEmail) {
506
+ primaryEmail = params.PrimaryEmail.toString().toLowerCase().trim();
507
+ secondaryEmail = params.SecondaryEmail.toString().toLowerCase().trim();
508
+ script += "let result:any = null ;\n let type:any = null;\n result = db[\"" + params.DataSet + "\"].Records.find((x: any)=>x.Email?.toString().toLowerCase().trim()===\"" + primaryEmail + "\"); \n if(result){\n // req.response = {...result}\n type = 'primary_email'\n // socket.write(JSON.stringify(req))\n }else{\n result = db[\"" + params.DataSet + "\"].Records.find((x: any)=>x.SecondaryEmail?.toString().toLowerCase().trim()===\"" + primaryEmail + "\"); \n if(result){\n // req.response = {...result}\n type= 'primary_email'\n // socket.write(JSON.stringify(req))\n }else{\n result = db[\"" + params.DataSet + "\"].Records.find((x: any)=>x.Email?.toString().toLowerCase().trim()===\"" + secondaryEmail + "\"); \n if(result){\n // req.response = {...result}\n type= 'secondary_email'\n // socket.write(JSON.stringify(req))\n }else{\n result = db[\"" + params.DataSet + "\"].Records.find((x: any)=>x.SecondaryEmail?.toString().toLowerCase().trim()===\"" + secondaryEmail + "\"); \n if(result){\n // req.response = {...result}\n type = 'secondary_email'\n // socket.write(JSON.stringify(req))\n }\n\n }\n }\n }\n if(result===null || result===undefined){\n socket.write(JSON.stringify(req))\n }else{\n req.response = {...result}\n req.response.type = type;\n socket.write(JSON.stringify(req))\n }";
509
+ }
510
+ else if (params.PrimaryEmail) {
511
+ primaryEmail_1 = params.PrimaryEmail.toString().toLowerCase().trim();
512
+ script += "let result = db[\"" + params.DataSet + "\"].Records.find((x: any)=>x.Email?.toString().toLowerCase().trim()===\"" + primaryEmail_1 + "\"); \n if(result){\n req.response = {...result}\n req.response.type = 'primary_email'\n socket.write(JSON.stringify(req))\n }else{\n let result:any = db[\"" + params.DataSet + "\"].Records.find((x: any)=>x.SecondaryEmail?.toString().toLowerCase().trim()===\"" + primaryEmail_1 + "\"); \n if(result){\n req.response = {...result}\n req.response.type = 'primary_email'\n socket.write(JSON.stringify(req))\n }\n }";
513
+ }
514
+ mongodbTransactionQueryopts = {};
515
+ return [4 /*yield*/, params.MemoryServerClient.Fetch('execute', { 'CompanyID': params.CompanyId, 'DataSet': params.DataSet, 'Script': script })];
516
+ case 1:
517
+ _a = _c.sent(), memoryServerSearchError = _a[0], memoryServerSearchData = _a[1];
518
+ if (!(memoryServerSearchData && Object.keys(memoryServerSearchData.response).length !== 0)) return [3 /*break*/, 4];
519
+ id = (_b = memoryServerSearchData === null || memoryServerSearchData === void 0 ? void 0 : memoryServerSearchData.response) === null || _b === void 0 ? void 0 : _b._id;
520
+ if (!(id && id !== '')) return [3 /*break*/, 3];
521
+ convertedToObjectID = new mongodb_1.ObjectID(id);
522
+ return [4 /*yield*/, params.db.collection(params.ProfileType).findOne({ '_id': convertedToObjectID }, mongodbTransactionQueryopts)];
523
+ case 2:
524
+ result = _c.sent();
525
+ if (result) {
526
+ result.Type = memoryServerSearchData.response.type;
527
+ resolve([null, result]);
528
+ }
529
+ else {
530
+ resolve([null, 'result not found']);
531
+ }
532
+ _c.label = 3;
533
+ case 3: return [3 /*break*/, 5];
534
+ case 4:
535
+ resolve([null, 'memory server search data not found']);
536
+ _c.label = 5;
537
+ case 5: return [3 /*break*/, 10];
538
+ case 6:
539
+ mongodbTransactionQueryopts = {};
540
+ return [4 /*yield*/, params.db.collection(params.ProfileType).find({}, { projection: { Email: 1, SecondaryEmail: 1, _id: 1 } }, mongodbTransactionQueryopts).toArray()];
541
+ case 7:
542
+ allContactData = _c.sent();
543
+ console.log(allContactData);
544
+ if (!(allContactData && allContactData.length > 0)) return [3 /*break*/, 10];
545
+ objectID = null;
546
+ type = "";
547
+ result = null;
548
+ if (params.PrimaryEmail && params.SecondaryEmail) {
549
+ primaryEmail_2 = params.PrimaryEmail.toString().toLowerCase().trim();
550
+ secondaryEmail_1 = params.SecondaryEmail.toString().toLowerCase().trim();
551
+ result = allContactData.find(function (x) { var _a; return ((_a = x.Email) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) === primaryEmail_2; });
552
+ if (result) {
553
+ objectID = result._id;
554
+ type = 'primary_email';
555
+ }
556
+ else {
557
+ result = allContactData.find(function (x) { var _a; return ((_a = x.SecondaryEmail) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) === primaryEmail_2; });
558
+ if (result) {
559
+ objectID = result._id;
560
+ type = 'primary_email';
561
+ }
562
+ else {
563
+ result = allContactData.find(function (x) { var _a; return ((_a = x.Email) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) === secondaryEmail_1; });
564
+ if (result) {
565
+ objectID = result._id;
566
+ type = 'secondary_email';
567
+ }
568
+ else {
569
+ result = allContactData.find(function (x) { var _a; return ((_a = x.SecondaryEmail) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) === secondaryEmail_1; });
570
+ if (result) {
571
+ objectID = result._id;
572
+ type = 'secondary_email';
573
+ }
574
+ }
575
+ }
576
+ }
577
+ }
578
+ else if (params.PrimaryEmail) {
579
+ primaryEmailrResult = allContactData.find(function (x) { var _a; return ((_a = x.Email) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) === params.PrimaryEmail; });
580
+ if (primaryEmailrResult) {
581
+ objectID = primaryEmailrResult._id;
582
+ type = 'primary_email';
583
+ }
584
+ else {
585
+ secondaryEmailResult = allContactData.find(function (x) { var _a; return ((_a = x.SecondaryEmail) === null || _a === void 0 ? void 0 : _a.toString().toLowerCase().trim()) === params.PrimaryEmail; });
586
+ if (secondaryEmailResult) {
587
+ type = 'primary_email';
588
+ objectID = primaryEmailrResult._id;
589
+ }
590
+ }
591
+ }
592
+ if (!(objectID === null)) return [3 /*break*/, 8];
593
+ resolve(null);
594
+ return [3 /*break*/, 10];
595
+ case 8:
596
+ if (!objectID) return [3 /*break*/, 10];
597
+ return [4 /*yield*/, params.db.collection(params.ProfileType).findOne({ '_id': objectID }, { projection: $project }, mongodbTransactionQueryopts)];
598
+ case 9:
599
+ result_1 = _c.sent();
600
+ if (result_1) {
601
+ result_1.Type = type;
602
+ resolve([null, result_1]);
603
+ }
604
+ else {
605
+ resolve([null, 'result not found']);
606
+ }
607
+ _c.label = 10;
608
+ case 10: return [3 /*break*/, 12];
609
+ case 11:
610
+ ex_3 = _c.sent();
611
+ resolve([ex_3, null]);
612
+ return [3 /*break*/, 12];
613
+ case 12: return [2 /*return*/];
614
+ }
615
+ });
616
+ }); })];
617
+ });
618
+ }); };
619
+ exports.EmailPrioritySearch = EmailPrioritySearch;
@@ -15,6 +15,7 @@ declare function GetPageFieldData(pageName: string, db: any, mdb: any, msp_d: an
15
15
  declare function GetPageObjectSchema(pageName: string, db: Db, next: NextFunction, callback: callBackInterface): void;
16
16
  declare function GetFieldDetail(objectName: string, fieldName: string, db: any, callback: callBackInterface, next: NextFunction): void;
17
17
  declare function UpdateRecentViewObject(objectName: string, objectID: ObjectID, userID: ObjectID, db: Db): void;
18
+ declare function UpdateRecentViewFields(objectName: string, fieldID: string, userID: ObjectID, db: Db): void;
18
19
  declare function SyncChildObjectData(pageData: AnyObjectInterface, objectID: ObjectID, db: Db): Promise<void>;
19
20
  declare function SyncParentObjectData(pageData: AnyObjectInterface, objectID: ObjectID, db: Db): Promise<void>;
20
21
  /**
@@ -38,6 +39,12 @@ declare function FilterConditions(condition: AnyObjectInterface, match: AnyObjec
38
39
  declare function GirdHeaderFilters(filters: AnyObjectInterface, fields: AnyObjectInterface): {
39
40
  $and: AnyObjectInterface[];
40
41
  };
42
+ declare function FieldsGridHeaderFilters(filters: AnyObjectInterface, fields: AnyObjectInterface): {
43
+ $and: AnyObjectInterface[];
44
+ lookupConditions: {
45
+ [x: number]: RegExp;
46
+ }[];
47
+ };
41
48
  /** @desc:{
42
49
  objectName: It's a name of Collection.
43
50
  logAction: Add | Modify | Delete
@@ -198,4 +205,4 @@ declare function ValidateSanitizeUserInput(inputFields: AnyObjectInterface, page
198
205
  * @return N/A
199
206
  */
200
207
  declare function CreateBanquetingVATSettingsData(msp_d: AnyObjectInterface, db: Db, sdata: AnyObjectInterface, next: NextFunction): Promise<void>;
201
- export { CheckForWhiteListedDomain, ReturnJsonResponse, ConvertFileByteSize, GetObjectByKeyValueFromList, IsEqualArrays, IsEqualValue, CheckUserProfileField, GetPageFieldData, GetPageObjectSchema, GetFieldDetail, UpdateRecentViewObject, SyncChildObjectData, SyncParentObjectData, DeleteFieldInOtherCollection, SyncFieldInSameCollection, SyncFieldInSameCollectionByObjectID, SyncFieldInSameCollectionByObjectIDWithPromise, SyncFieldInOtherCollection, SyncUserInOtherCollection, BuildLookupDataField, CheckDataBeforeAdd, CheckDataBeforeUpdate, BuildGridFieldProjection, BuildFieldProjection, BuildLookupFieldProjection, FilterConditions, GirdHeaderFilters, AddLog, CheckFilterFieldsProjection, VerifyEmailPassword, GetMyTeamUsers, ExtractChildUsersTree, GetMaxKeyValueListSchema, VerifyAWSEmailConfig, GenerateId, SyncUserDetailsWithMasterDB, SignoutUserFromAllDevices, SignoutUsersWithPromise, SignoutMultipleUsersFromAllDevices, UserLicenseConsumeCalculate, sendMailWithUserAccount, GetEmailClientConfigs, GetCompanyEncryptionKey, ExecuteDynamicDMLQuery, ExecuteDynamicDQLQuery, GetUserProfilePermissions, MakeUserPasswordInvalid, ConvertJsonToXLXS, SendResetPasswordMail, SendMailToSupport, MailTemplateStructure, SendMailToCustomer, parseMSPCookie, GetIPDetailsFromReq, isEmptyObj, SyncListSchemaFieldInOtherCollection, UpdateTagCountAfterDelete, SyncTagCountAfterUpdate, ReactivateFieldInOtherCollection, SyncUserLicenceConsumedCount, BroadCastEventToAllCompanyUsers, CheckDataPermission, SyncCompanyLicenceInMasterCompanyAfterAdd, NextServiceDateForDashboard, CheckDateNotInPast, GetWeekDayByDayAndOccurance, GetInterValFromOccurance, GetWeekDayInfoInMonth, GetDayIndex, RemoveFieldsFromFilters, GetUserProfile, CheckPageAuthentication, ErrorHandlerForServices, CheckCaptcha, ValidateSanitizeUserInput, CreateBanquetingVATSettingsData };
208
+ export { CheckForWhiteListedDomain, ReturnJsonResponse, ConvertFileByteSize, GetObjectByKeyValueFromList, IsEqualArrays, IsEqualValue, CheckUserProfileField, GetPageFieldData, GetPageObjectSchema, GetFieldDetail, UpdateRecentViewObject, UpdateRecentViewFields, SyncChildObjectData, SyncParentObjectData, DeleteFieldInOtherCollection, SyncFieldInSameCollection, SyncFieldInSameCollectionByObjectID, SyncFieldInSameCollectionByObjectIDWithPromise, SyncFieldInOtherCollection, SyncUserInOtherCollection, BuildLookupDataField, CheckDataBeforeAdd, CheckDataBeforeUpdate, BuildGridFieldProjection, BuildFieldProjection, BuildLookupFieldProjection, FilterConditions, GirdHeaderFilters, FieldsGridHeaderFilters, AddLog, CheckFilterFieldsProjection, VerifyEmailPassword, GetMyTeamUsers, ExtractChildUsersTree, GetMaxKeyValueListSchema, VerifyAWSEmailConfig, GenerateId, SyncUserDetailsWithMasterDB, SignoutUserFromAllDevices, SignoutUsersWithPromise, SignoutMultipleUsersFromAllDevices, UserLicenseConsumeCalculate, sendMailWithUserAccount, GetEmailClientConfigs, GetCompanyEncryptionKey, ExecuteDynamicDMLQuery, ExecuteDynamicDQLQuery, GetUserProfilePermissions, MakeUserPasswordInvalid, ConvertJsonToXLXS, SendResetPasswordMail, SendMailToSupport, MailTemplateStructure, SendMailToCustomer, parseMSPCookie, GetIPDetailsFromReq, isEmptyObj, SyncListSchemaFieldInOtherCollection, UpdateTagCountAfterDelete, SyncTagCountAfterUpdate, ReactivateFieldInOtherCollection, SyncUserLicenceConsumedCount, BroadCastEventToAllCompanyUsers, CheckDataPermission, SyncCompanyLicenceInMasterCompanyAfterAdd, NextServiceDateForDashboard, CheckDateNotInPast, GetWeekDayByDayAndOccurance, GetInterValFromOccurance, GetWeekDayInfoInMonth, GetDayIndex, RemoveFieldsFromFilters, GetUserProfile, CheckPageAuthentication, ErrorHandlerForServices, CheckCaptcha, ValidateSanitizeUserInput, CreateBanquetingVATSettingsData };