@optimiser/common 1.0.264 → 1.0.267

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.
@@ -316,25 +316,54 @@ var Connection = /** @class */ (function () {
316
316
  */
317
317
  Connection.prototype.FindAndReturnDBConnection = function (DBName, DBAddress) {
318
318
  var _this = this;
319
+ /*Code Updated By Suraj on 07-Apr-2022, Try catch and some If conditions added to prevent from breaking the code.*/
319
320
  return new Promise(function (resolve, reject) {
320
- if (DBAddress && _this.connections[Buffer.from(DBAddress).toString('base64')]) {
321
- _this.connections[Buffer.from(DBAddress).toString('base64')].db(DBName);
322
- }
323
- var masterDb = _this.connections[Buffer.from(_this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')].db(_this.masterConfig.MASTER_DB_NAME);
324
- if (DBName == _this.masterConfig.MASTER_DB_NAME) {
325
- return resolve(masterDb);
326
- }
327
- masterDb.collection("Company").findOne({ DBName: DBName }).then(function (companyData) {
328
- if (companyData) {
329
- _this.ConnectToDb({
330
- DBAddress: companyData.DBAddress,
331
- DBName: companyData.DBName
332
- }).then(function (success) { return resolve(_this.connections[Buffer.from(companyData.DBAddress).toString('base64')].db(companyData.DBName)); });
321
+ try {
322
+ if (DBAddress && _this.connections[Buffer.from(DBAddress).toString('base64')]) {
323
+ _this.connections[Buffer.from(DBAddress).toString('base64')].db(DBName);
324
+ }
325
+ var masterDb = null;
326
+ if (_this.connections[Buffer.from(_this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')]) {
327
+ masterDb = _this.connections[Buffer.from(_this.masterConfig.MASTER_CONNECTION_STRING).toString('base64')].db(_this.masterConfig.MASTER_DB_NAME);
328
+ }
329
+ //checking master db connection
330
+ if (!masterDb) {
331
+ console.log("Master db connection not available");
332
+ reject(new Error("Master db connection not available"));
333
+ return;
333
334
  }
334
- else {
335
- reject();
335
+ if (DBName == _this.masterConfig.MASTER_DB_NAME) {
336
+ return resolve(masterDb);
336
337
  }
337
- }, function (error) { return reject(error); });
338
+ masterDb.collection("Company").findOne({ DBName: DBName }).then(function (companyData) {
339
+ if (companyData) {
340
+ _this.ConnectToDb({
341
+ DBAddress: companyData.DBAddress,
342
+ DBName: companyData.DBName
343
+ }).then(function () {
344
+ //Checking company connection first, if exists then resolve
345
+ if (_this.connections[Buffer.from(companyData.DBAddress).toString('base64')]) {
346
+ resolve(_this.connections[Buffer.from(companyData.DBAddress).toString('base64')].db(companyData.DBName));
347
+ }
348
+ else {
349
+ console.log("Company db connection not established");
350
+ reject(new Error("Company db connection not established"));
351
+ }
352
+ });
353
+ }
354
+ else {
355
+ reject();
356
+ }
357
+ }, function (error) {
358
+ console.log("Error occurred :", error);
359
+ reject(error);
360
+ });
361
+ }
362
+ catch (ex) {
363
+ console.log("Error occurred :", ex);
364
+ ex.message += "- db connection error";
365
+ reject(ex);
366
+ }
338
367
  });
339
368
  };
340
369
  /**
@@ -344,7 +373,6 @@ var Connection = /** @class */ (function () {
344
373
  */
345
374
  Connection.prototype.ConnectToCompanyDB = function (DBName, DBAddress) {
346
375
  return __awaiter(this, void 0, void 0, function () {
347
- var masterdb;
348
376
  return __generator(this, function (_a) {
349
377
  switch (_a.label) {
350
378
  case 0:
@@ -355,7 +383,7 @@ var Connection = /** @class */ (function () {
355
383
  DBName: this.masterConfig.MASTER_DB_NAME
356
384
  })];
357
385
  case 2:
358
- masterdb = _a.sent();
386
+ _a.sent();
359
387
  return [2 /*return*/, this.FindAndReturnDBConnection(DBName, DBAddress)];
360
388
  }
361
389
  });
@@ -395,7 +423,7 @@ var Connection = /** @class */ (function () {
395
423
  Type: "ERROR"
396
424
  })];
397
425
  }
398
- db.collection("User").findOne({ _id: new mongodb_1.ObjectID(req.cookies.msp_d.ui) }).then(function (user) {
426
+ db.collection("User").findOne({ _id: new mongodb_1.ObjectId(req.cookies.msp_d.ui) }).then(function (user) {
399
427
  if (!user) {
400
428
  return _this.ReturnJsonResponse(req, res, {
401
429
  Data: {},
package/dist/lib/event.js CHANGED
@@ -57,7 +57,7 @@ var Event = /** @class */ (function () {
57
57
  switch (_a.label) {
58
58
  case 0:
59
59
  if (!(db && userId && data && data.PushNotificationObj && !data.PushNotificationObj["endpoint"])) return [3 /*break*/, 2];
60
- return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectID(userId) })];
60
+ return [4 /*yield*/, db.collection('UserNotification').findOne({ UserID: new mongodb_1.ObjectId(userId) })];
61
61
  case 1:
62
62
  userObj = _a.sent();
63
63
  if (userObj && userObj.endpoint && userObj.keys && data.PushNotificationObj) {
@@ -130,8 +130,8 @@ var Event = /** @class */ (function () {
130
130
  CreatedDate: new Date(),
131
131
  Users: [],
132
132
  EventObjectName: data.EventObjectName,
133
- EventID: new mongodb_1.ObjectID(data.EventID),
134
- CreatedBy: new mongodb_1.ObjectID(data.CreatedBy),
133
+ EventID: new mongodb_1.ObjectId(data.EventID),
134
+ CreatedBy: new mongodb_1.ObjectId(data.CreatedBy),
135
135
  Message: data.Message
136
136
  };
137
137
  var Userid = [];
@@ -139,7 +139,7 @@ var Event = /** @class */ (function () {
139
139
  Userid.push({
140
140
  "IsSeen": false,
141
141
  "IsNew": true,
142
- "UserID": new mongodb_1.ObjectID(id)
142
+ "UserID": new mongodb_1.ObjectId(id)
143
143
  });
144
144
  });
145
145
  saveObj.Users = Userid;
@@ -1,4 +1,4 @@
1
- import { Db, ObjectID } from "mongodb";
1
+ import { Db, ObjectId } from "mongodb";
2
2
  import { AnyObjectInterface } from "../modals/utility.modal";
3
3
  declare function GetCompanyDetails(Master_DB: Db, companyId: string): Promise<any>;
4
4
  declare function GetListSchema(db: Db, listName: string): Promise<Error | AnyObjectInterface[] | []>;
@@ -6,7 +6,7 @@ declare function GetEmailwiseUnsubscribeData(db: Db, mailID: string, domainID?:
6
6
  declare function GenerateAutoIncrementFieldValue(db: Db, autoIncrementID: string): Promise<null | string>;
7
7
  declare function GetAccountDetailByName(db: Db, accountName: string): Promise<AnyObjectInterface | null>;
8
8
  declare function GetContactDetailByEmail(db: Db, contactEmail: string): Promise<null | AnyObjectInterface>;
9
- declare function GetSystemEmailTemplate(db: Db, TemplateIDArray: ObjectID[]): Promise<null | AnyObjectInterface>;
9
+ declare function GetSystemEmailTemplate(db: Db, TemplateIDArray: ObjectId[]): Promise<null | AnyObjectInterface>;
10
10
  declare function UpdateContactDetails(db: Db, contactData: AnyObjectInterface): void;
11
11
  declare function CreateContact(db: Db, contactData: AnyObjectInterface): Promise<null | AnyObjectInterface>;
12
12
  declare function MapAccountContact(db: Db, dataObj: AnyObjectInterface): void;
@@ -50,7 +50,7 @@ declare const GetEmailSubscribeStatus: (db: Db, email: string) => Promise<Error
50
50
  * @param {mongodbQueryOptions} object, params to pass on db queries
51
51
  * @returns resolve success | error object
52
52
  */
53
- declare const SubscribeEmailForAllDomains: (db: Db, email: string, isSubscribe: boolean, companyID: ObjectID, comment?: string, mongodbQueryOptions?: any) => Promise<unknown>;
53
+ declare const SubscribeEmailForAllDomains: (db: Db, email: string, isSubscribe: boolean, companyID: ObjectId, comment?: string, mongodbQueryOptions?: any) => Promise<unknown>;
54
54
  /**
55
55
  * checking phone number is valid and has dialing code
56
56
  * if it has dialing code then get country code, get its optimiser country phone code
@@ -45,7 +45,7 @@ var constants_1 = __importDefault(require("../constants"));
45
45
  var moment_1 = __importDefault(require("moment"));
46
46
  var libphonenumber_js_1 = require("libphonenumber-js");
47
47
  function GetCompanyDetails(Master_DB, companyId) {
48
- return Master_DB.collection('Company').findOne({ _id: new mongodb_1.ObjectID(companyId) });
48
+ return Master_DB.collection('Company').findOne({ _id: new mongodb_1.ObjectId(companyId) });
49
49
  }
50
50
  exports.GetCompanyDetails = GetCompanyDetails;
51
51
  function GetListSchema(db, listName) {
@@ -519,7 +519,7 @@ var EmailPrioritySearch = function (params) { return __awaiter(void 0, void 0, v
519
519
  if (!(memoryServerSearchData && Object.keys(memoryServerSearchData.response).length !== 0)) return [3 /*break*/, 4];
520
520
  id = (_b = memoryServerSearchData === null || memoryServerSearchData === void 0 ? void 0 : memoryServerSearchData.response) === null || _b === void 0 ? void 0 : _b._id;
521
521
  if (!(id && id !== '')) return [3 /*break*/, 3];
522
- convertedToObjectID = new mongodb_1.ObjectID(id);
522
+ convertedToObjectID = new mongodb_1.ObjectId(id);
523
523
  return [4 /*yield*/, params.db.collection(params.ProfileType).findOne({ '_id': convertedToObjectID }, mongodbTransactionQueryopts)];
524
524
  case 2:
525
525
  result = _c.sent();
@@ -157,7 +157,7 @@ function GenerateTaskNotifications(req, options, db, event) {
157
157
  if (!tasks_1[0].ListSublist)
158
158
  return [2 /*return*/];
159
159
  return [4 /*yield*/, db.collection('TaskList').findOne({
160
- _id: new mongodb_1.ObjectID(tasks_1[0].ListSublist)
160
+ _id: new mongodb_1.ObjectId(tasks_1[0].ListSublist)
161
161
  })];
162
162
  case 3:
163
163
  list = _b.sent();
@@ -179,12 +179,12 @@ function GenerateTaskNotifications(req, options, db, event) {
179
179
  info['taskBeforeEdit'] = options.taskBeforeEdit;
180
180
  return [3 /*break*/, 8];
181
181
  case 4: return [4 /*yield*/, db.collection('Task').findOne({
182
- _id: new mongodb_1.ObjectID(options.taskID)
182
+ _id: new mongodb_1.ObjectId(options.taskID)
183
183
  })];
184
184
  case 5:
185
185
  task = _b.sent();
186
186
  return [4 /*yield*/, db.collection('TaskList').findOne({
187
- _id: new mongodb_1.ObjectID(task.ListSublist)
187
+ _id: new mongodb_1.ObjectId(task.ListSublist)
188
188
  })];
189
189
  case 6:
190
190
  list = _b.sent();
@@ -262,10 +262,10 @@ function CreateNotificationContent(info, req, db, event) {
262
262
  return __generator(this, function (_b) {
263
263
  switch (_b.label) {
264
264
  case 0:
265
- UserID = new mongodb_1.ObjectID(req.cookies.msp_d.ui);
265
+ UserID = new mongodb_1.ObjectId(req.cookies.msp_d.ui);
266
266
  Payload = {};
267
267
  FetchUsers = function (query) { return db.collection('User').find(query).toArray(); };
268
- ListInfo = function (id) { return db.collection('TaskList').findOne({ _id: new mongodb_1.ObjectID(id) }); };
268
+ ListInfo = function (id) { return db.collection('TaskList').findOne({ _id: new mongodb_1.ObjectId(id) }); };
269
269
  TaskInfo = function (TaskNumber) { return db.collection('Task').findOne({ TaskNumber: TaskNumber }); };
270
270
  NotificationContent = {};
271
271
  _a = info.page;
@@ -354,7 +354,7 @@ function CreateNotificationContent(info, req, db, event) {
354
354
  creator = _b.sent();
355
355
  creator = creator[0];
356
356
  return [3 /*break*/, 13];
357
- case 11: return [4 /*yield*/, FetchUsers({ _id: new mongodb_1.ObjectID(info.receiverId), "UserStatus": { $not: { $eq: "Blocked" } } })];
357
+ case 11: return [4 /*yield*/, FetchUsers({ _id: new mongodb_1.ObjectId(info.receiverId), "UserStatus": { $not: { $eq: "Blocked" } } })];
358
358
  case 12:
359
359
  users = _b.sent();
360
360
  creator = info.senderData[0];
@@ -398,7 +398,7 @@ function CreateNotificationContent(info, req, db, event) {
398
398
  if (!(info.event == 'EDIT_TASK')) return [3 /*break*/, 17];
399
399
  if ((req.body.AssignedTo ? req.body.AssignedTo.$oid : (oldTaskData.AssignedTo).toString()) == (oldTaskData.OwnerID).toString())
400
400
  return [2 /*return*/];
401
- receiverId_1 = new mongodb_1.ObjectID((req.cookies.msp_d.ui == (oldTaskData.AssignedTo).toString()) ? oldTaskData.OwnerID : (oldTaskData.AssignedTo).toString());
401
+ receiverId_1 = new mongodb_1.ObjectId((req.cookies.msp_d.ui == (oldTaskData.AssignedTo).toString()) ? oldTaskData.OwnerID : (oldTaskData.AssignedTo).toString());
402
402
  return [4 /*yield*/, FetchUsers({
403
403
  _id: receiverId_1,
404
404
  "UserStatus": { $not: { $eq: "Blocked" } }
@@ -492,7 +492,7 @@ function CreateNotificationContent(info, req, db, event) {
492
492
  return [3 /*break*/, 20];
493
493
  case 17:
494
494
  if (!(info.event == "EDIT_TASK_INLINE")) return [3 /*break*/, 20];
495
- receiverId_2 = new mongodb_1.ObjectID((req.cookies.msp_d.ui == (oldTaskData.AssignedTo).toString()) ? oldTaskData.OwnerID : (oldTaskData.AssignedTo).toString());
495
+ receiverId_2 = new mongodb_1.ObjectId((req.cookies.msp_d.ui == (oldTaskData.AssignedTo).toString()) ? oldTaskData.OwnerID : (oldTaskData.AssignedTo).toString());
496
496
  return [4 /*yield*/, FetchUsers({ _id: receiverId_2, "UserStatus": { $not: { $eq: "Blocked" } } })];
497
497
  case 18:
498
498
  receiverData_2 = _b.sent();
@@ -1,6 +1,6 @@
1
1
  import { Moment } from "moment";
2
2
  import { NextFunction, Response } from "express";
3
- import { ObjectID, ObjectId, Db } from "mongodb";
3
+ import { ObjectId, Db } from "mongodb";
4
4
  import { ResponseStructure, OPT_ERROR } from "../modals/connection.modal";
5
5
  import { Express } from '../modals/log.modal';
6
6
  import { AnyObjectInterface, callBackInterface } from "../modals/utility.modal";
@@ -14,10 +14,10 @@ declare function CheckUserProfileField(pageData: AnyObjectInterface, profileData
14
14
  declare function GetPageFieldData(pageName: string, db: any, mdb: any, msp_d: any, next: NextFunction, callback: callBackInterface): void;
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
- 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;
19
- declare function SyncChildObjectData(pageData: AnyObjectInterface, objectID: ObjectID, db: Db): Promise<void>;
20
- declare function SyncParentObjectData(pageData: AnyObjectInterface, objectID: ObjectID, db: Db): Promise<void>;
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;
19
+ declare function SyncChildObjectData(pageData: AnyObjectInterface, objectID: ObjectId, db: Db): Promise<void>;
20
+ declare function SyncParentObjectData(pageData: AnyObjectInterface, objectID: ObjectId, db: Db): Promise<void>;
21
21
  /**
22
22
  * Delete field in other collection after delete records
23
23
  * @param mongodbTransactionQueryopts to maintain session for transactions
@@ -1348,7 +1348,7 @@ function SyncUserInOtherCollection(options, db, callback, next) {
1348
1348
  else if (field.UIDataType == "multilookup") {
1349
1349
  query.match = (_b = {}, _b[field.Name] = { "$nin": [null] }, _b[field.Name + constants_1.default.LookupAlias] = { "$nin": [null] }, _b);
1350
1350
  query.set[field.Name + '.$[e]'] = userData["toUserData"]._id;
1351
- query.set["ModifiedBy"] = new mongodb_1.ObjectID(msp_d.ui);
1351
+ query.set["ModifiedBy"] = new mongodb_1.ObjectId(msp_d.ui);
1352
1352
  query.set["ModifiedDate"] = new Date();
1353
1353
  query.arrayFilters = (_c = {}, _c['e._id'] = userData["fromUserData"]._id, _c);
1354
1354
  if (query.set && query.arrayFilters)
@@ -1420,12 +1420,29 @@ exports.SyncUserInOtherCollection = SyncUserInOtherCollection;
1420
1420
  //Build _LookupDataField before save
1421
1421
  function BuildLookupDataField(fieldSchema, updateObj, db) {
1422
1422
  return new Promise(function (resolve, reject) {
1423
+ /**
1424
+ * Added By Suraj on 06-Apr-2022,
1425
+ * helper function for all below cases to print error log on console.
1426
+ * @param fieldValue value of a field
1427
+ * @param err error occurred during processing
1428
+ */
1429
+ var errorHandler = function (fieldValue, err) {
1430
+ var fieldValueType = (Array.isArray(fieldValue) ? 'array' : '');
1431
+ if (!fieldValueType) {
1432
+ fieldValueType = typeof (fieldValue);
1433
+ }
1434
+ var errorInfo = "##### COMMON MOUDLE ERROR INFO ####";
1435
+ errorInfo += "\n Function Name : BuildLookupDataField";
1436
+ errorInfo += "\n Error Info: Error while building Lookup Data for Company - " + (db.databaseName) + ", ObjectName - " + (fieldSchema.LookupObject || '') + ", FieldName - " + (fieldSchema.Name || '') + " for value - " + fieldValue + " and data type of values is " + (fieldValueType || '') + " ";
1437
+ console.log("Error Information : ", errorInfo);
1438
+ console.log("Error Full Object : ", err);
1439
+ };
1423
1440
  if (fieldSchema.UIDataType && constants_1.default.LookupTypeFields.includes(fieldSchema.UIDataType)) {
1424
1441
  var fldName = fieldSchema.Name;
1425
- var fldValue = updateObj[fldName];
1442
+ var fldValue_1 = updateObj[fldName];
1426
1443
  var alias_1 = fldName + constants_1.default.LookupAlias;
1427
1444
  var fldLookupData_1 = null;
1428
- if (fldValue) {
1445
+ if (fldValue_1) {
1429
1446
  var aggregateArry = [];
1430
1447
  var project = { '_id': 1, IsActive: 1 };
1431
1448
  if (fieldSchema.ExtraLookupObjects) {
@@ -1456,13 +1473,13 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1456
1473
  }
1457
1474
  switch (fieldSchema.UIDataType) {
1458
1475
  case "lookup":
1459
- aggregateArry.push({ $match: { '_id': fldValue } });
1476
+ aggregateArry.push({ $match: { '_id': fldValue_1 } });
1460
1477
  aggregateArry.push({ $project: project });
1461
1478
  db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err, data) {
1462
1479
  if (err) {
1463
- //not handel
1480
+ errorHandler(fldValue_1, err);
1464
1481
  }
1465
- if (data && data.length > 0) {
1482
+ else if (data && data.length > 0) {
1466
1483
  fldLookupData_1 = data[0];
1467
1484
  updateObj[alias_1] = fldLookupData_1;
1468
1485
  }
@@ -1470,7 +1487,7 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1470
1487
  });
1471
1488
  break;
1472
1489
  case "multilookup":
1473
- aggregateArry.push({ $match: { '_id': { $in: fldValue } } });
1490
+ aggregateArry.push({ $match: { '_id': { $in: fldValue_1 } } });
1474
1491
  aggregateArry.push({ $project: project });
1475
1492
  if (fieldSchema.UnionWith && fieldSchema.UnionWith.length > 0) {
1476
1493
  for (var i = 0; i < fieldSchema.UnionWith.length; i++) {
@@ -1478,7 +1495,7 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1478
1495
  if (unionDetail) {
1479
1496
  var unionPipeline = [];
1480
1497
  unionPipeline.push({
1481
- $match: { '_id': { $in: fldValue } }
1498
+ $match: { '_id': { $in: fldValue_1 } }
1482
1499
  });
1483
1500
  unionPipeline.push({ $project: project });
1484
1501
  var unionObj = { coll: unionDetail.LookupObject, pipeline: unionPipeline };
@@ -1488,9 +1505,10 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1488
1505
  }
1489
1506
  db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err, data) {
1490
1507
  if (err) {
1491
- throw new Error(err.toString());
1508
+ // throw new Error(err.toString());
1509
+ errorHandler(fldValue_1, err);
1492
1510
  }
1493
- if (data && data.length > 0) {
1511
+ else if (data && data.length > 0) {
1494
1512
  fldLookupData_1 = data;
1495
1513
  updateObj[alias_1] = fldLookupData_1;
1496
1514
  }
@@ -1499,13 +1517,13 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1499
1517
  break;
1500
1518
  case "dropdown":
1501
1519
  if (fieldSchema.LookupObject) {
1502
- aggregateArry.push({ $match: { _id: fldValue } });
1520
+ aggregateArry.push({ $match: { _id: fldValue_1 } });
1503
1521
  aggregateArry.push({ $project: project });
1504
1522
  db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err, data) {
1505
1523
  if (err) {
1506
- //not handel
1524
+ errorHandler(fldValue_1, err);
1507
1525
  }
1508
- if (data && data.length > 0) {
1526
+ else if (data && data.length > 0) {
1509
1527
  fldLookupData_1 = data[0];
1510
1528
  updateObj[alias_1] = fldLookupData_1;
1511
1529
  }
@@ -1521,12 +1539,12 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1521
1539
  }
1522
1540
  aggregateArry.push({ $unwind: { path: '$Data' } });
1523
1541
  aggregateArry.push({ $project: { _id: 0, Key: '$Data.Key', Value: '$Data.Value', IsActive: '$Data.IsActive' } });
1524
- aggregateArry.push({ $match: { 'Key': fldValue } });
1542
+ aggregateArry.push({ $match: { 'Key': fldValue_1 } });
1525
1543
  db.collection('ListSchema').aggregate(aggregateArry).toArray(function (err, data) {
1526
1544
  if (err) {
1527
- //not handel
1545
+ errorHandler(fldValue_1, err);
1528
1546
  }
1529
- if (data && data.length > 0) {
1547
+ else if (data && data.length > 0) {
1530
1548
  fldLookupData_1 = data[0];
1531
1549
  updateObj[alias_1] = fldLookupData_1;
1532
1550
  }
@@ -1536,13 +1554,13 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1536
1554
  break;
1537
1555
  case "multiselect":
1538
1556
  if (fieldSchema.LookupObject) {
1539
- aggregateArry.push({ $match: { '_id': { $in: fldValue } } });
1557
+ aggregateArry.push({ $match: { '_id': { $in: fldValue_1 } } });
1540
1558
  aggregateArry.push({ $project: project });
1541
1559
  db.collection(fieldSchema.LookupObject).aggregate(aggregateArry).toArray(function (err, data) {
1542
1560
  if (err) {
1543
- //not handel
1561
+ errorHandler(fldValue_1, err);
1544
1562
  }
1545
- if (data && data.length > 0) {
1563
+ else if (data && data.length > 0) {
1546
1564
  fldLookupData_1 = data;
1547
1565
  updateObj[alias_1] = fldLookupData_1;
1548
1566
  }
@@ -1553,12 +1571,12 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1553
1571
  aggregateArry.push({ $match: { 'Name': fieldSchema.ListSchemaName } });
1554
1572
  aggregateArry.push({ $unwind: { path: '$Data' } });
1555
1573
  aggregateArry.push({ $project: { _id: 0, Key: '$Data.Key', Value: '$Data.Value', IsActive: '$Data.IsActive' } });
1556
- aggregateArry.push({ $match: { 'Key': { $in: fldValue } } });
1574
+ aggregateArry.push({ $match: { 'Key': { $in: fldValue_1 } } });
1557
1575
  db.collection('ListSchema').aggregate(aggregateArry).toArray(function (err, data) {
1558
1576
  if (err) {
1559
- //not handel
1577
+ errorHandler(fldValue_1, err);
1560
1578
  }
1561
- if (data && data.length > 0) {
1579
+ else if (data && data.length > 0) {
1562
1580
  fldLookupData_1 = data;
1563
1581
  updateObj[alias_1] = fldLookupData_1;
1564
1582
  }
@@ -1569,14 +1587,14 @@ function BuildLookupDataField(fieldSchema, updateObj, db) {
1569
1587
  case "file":
1570
1588
  case "image":
1571
1589
  if (!fieldSchema.IsMultiple) {
1572
- aggregateArry.push({ $match: { '_id': fldValue } });
1590
+ aggregateArry.push({ $match: { '_id': fldValue_1 } });
1573
1591
  project['FileName'] = 1;
1574
1592
  aggregateArry.push({ $project: project });
1575
1593
  db.collection('Drive').aggregate(aggregateArry).toArray(function (err, data) {
1576
1594
  if (err) {
1577
- //not handel
1595
+ errorHandler(fldValue_1, err);
1578
1596
  }
1579
- if (data && data.length > 0) {
1597
+ else if (data && data.length > 0) {
1580
1598
  fldLookupData_1 = data[0];
1581
1599
  updateObj[alias_1] = fldLookupData_1;
1582
1600
  }
@@ -2032,7 +2050,7 @@ function FilterConditions(condition, match, fields) {
2032
2050
  case "multiselect":
2033
2051
  if (field.Schema.LookupObject) {
2034
2052
  for (var i_7 = 0; i_7 < obj.Value.length; i_7++) {
2035
- obj.Value[i_7] = new mongodb_1.ObjectID(obj.Value[i_7]);
2053
+ obj.Value[i_7] = new mongodb_1.ObjectId(obj.Value[i_7]);
2036
2054
  }
2037
2055
  }
2038
2056
  break;
@@ -2153,9 +2171,19 @@ function GirdHeaderFilters(filters, fields) {
2153
2171
  var matchValue = null;
2154
2172
  var fldName = field.UniqueID;
2155
2173
  if (["lookup", "multilookup"].includes(field.Schema.UIDataType)) {
2156
- fldName += '_SearchValue';
2174
+ //added by nirbhay on 12 apr 2022, added dropdown and multiselect for lookup and multilookup field
2175
+ if (field.Schema.SearchType == 'dropdown') {
2176
+ matchValue = { '$eq': bson_1.EJSON.parse(JSON.stringify(obj.Value)) };
2177
+ }
2178
+ else if (field.Schema.SearchType == 'multiselect') {
2179
+ matchValue = { '$in': bson_1.EJSON.parse(JSON.stringify(obj.Value)) };
2180
+ }
2181
+ else {
2182
+ fldName += '_SearchValue';
2183
+ matchValue = { '$regex': obj.Value.trim().replace(/[-[\]{}()*+?.,\\/^$|#\s]/g, "\\$&"), '$options': 'i' };
2184
+ }
2157
2185
  }
2158
- if (["dropdown", "multiselect"].includes(field.Schema.UIDataType)) {
2186
+ else if (["dropdown", "multiselect"].includes(field.Schema.UIDataType)) {
2159
2187
  if (field.Schema.LookupObject) {
2160
2188
  matchValue = { '$in': bson_1.EJSON.parse(JSON.stringify(obj.Value)) };
2161
2189
  }
@@ -2178,6 +2206,10 @@ function GirdHeaderFilters(filters, fields) {
2178
2206
  else if (["decimal", "percent"].includes(field.Schema.UIDataType))
2179
2207
  matchValue = { '$eq': mongodb_1.Decimal128.fromString(obj.Value) };
2180
2208
  else if (field.Schema.UIDataType == 'objectid')
2209
+ matchValue = { '$eq': bson_1.EJSON.parse(JSON.stringify(obj.Value)) };
2210
+ else if (field.Schema.IsEqualAndCaseInsensitiveSearch === true)
2211
+ matchValue = new RegExp('^' + obj.Value + '$', 'i');
2212
+ else if (field.Schema.IsEqualSearch === true)
2181
2213
  matchValue = { '$eq': obj.Value };
2182
2214
  else
2183
2215
  matchValue = { '$regex': obj.Value.trim().replace(/[-[\]{}()*+?.,\\/^$|#\s]/g, "\\$&"), '$options': 'i' };
@@ -2258,7 +2290,7 @@ function AddLog(req, objectName, logAction, objLogProp, db, next) {
2258
2290
  logObj.Action = logAction;
2259
2291
  if (objLogProp.ObjectID)
2260
2292
  if (objLogProp.ObjectID.$oid) {
2261
- logObj.ObjectID = new mongodb_1.ObjectID(objLogProp.ObjectID.$oid);
2293
+ logObj.ObjectID = new mongodb_1.ObjectId(objLogProp.ObjectID.$oid);
2262
2294
  }
2263
2295
  else {
2264
2296
  logObj.ObjectID = objLogProp.ObjectID;
@@ -2352,7 +2384,7 @@ caledar sharing settings : caledar sharing settings
2352
2384
  function GetMyTeamUsers(options, next) {
2353
2385
  var usersList = [];
2354
2386
  var db = options.db;
2355
- db.collection("Company").findOne({ '_id': new mongodb_1.ObjectID(options.CompanyID) }, function (error, result) {
2387
+ db.collection("Company").findOne({ '_id': new mongodb_1.ObjectId(options.CompanyID) }, function (error, result) {
2356
2388
  if (result) {
2357
2389
  var calendarSetting = result.Setting;
2358
2390
  if (calendarSetting.CalendarShare == "private") {
@@ -2388,8 +2420,8 @@ function GetMyTeamUsers(options, next) {
2388
2420
  pendingCalls_1 = pendingCalls_1 - 1;
2389
2421
  db.collection("User").find({
2390
2422
  $or: [
2391
- { '_id': new mongodb_1.ObjectID(options.SupervisorID) },
2392
- { 'SupervisorID': new mongodb_1.ObjectID(options.SupervisorID) }
2423
+ { '_id': new mongodb_1.ObjectId(options.SupervisorID) },
2424
+ { 'SupervisorID': new mongodb_1.ObjectId(options.SupervisorID) }
2393
2425
  ],
2394
2426
  'IsActive': true,
2395
2427
  "MySettings.IsHideFromAllUsers": { $ne: true }
@@ -2434,7 +2466,7 @@ function GetMyTeamUsers(options, next) {
2434
2466
  counter_2 = counter_2 + 1;
2435
2467
  pendingCalls_2 = pendingCalls_2 - 1;
2436
2468
  db.collection("User").find({
2437
- 'SupervisorID': new mongodb_1.ObjectID(options.SupervisorID),
2469
+ 'SupervisorID': new mongodb_1.ObjectId(options.SupervisorID),
2438
2470
  'IsActive': true,
2439
2471
  "MySettings.IsHideFromAllUsers": { $ne: true }
2440
2472
  }, { projection: { _id: 1, FirstName: 1, LastName: 1, UserStatus: 1 } }).toArray(function (error, result) {
@@ -2483,7 +2515,7 @@ function GetMyTeamUsers(options, next) {
2483
2515
  }
2484
2516
  exports.GetMyTeamUsers = GetMyTeamUsers;
2485
2517
  function ExtractChildUsersTree(userId, childUsersArray, usersTraversed, counter, db, onFetch) {
2486
- db.collection("User").find({ 'IsActive': true, 'SupervisorID': new mongodb_1.ObjectID(userId), "MySettings.IsHideFromAllUsers": { $ne: true } }, { projection: { _id: 1, FirstName: 1, LastName: 1, UserStatus: 1 } }).toArray(function (error, result) {
2518
+ db.collection("User").find({ 'IsActive': true, 'SupervisorID': new mongodb_1.ObjectId(userId), "MySettings.IsHideFromAllUsers": { $ne: true } }, { projection: { _id: 1, FirstName: 1, LastName: 1, UserStatus: 1 } }).toArray(function (error, result) {
2487
2519
  if (error) {
2488
2520
  //res.json({ message: err.message, status: 'failed' })
2489
2521
  }
@@ -2550,7 +2582,7 @@ exports.VerifyAWSEmailConfig = VerifyAWSEmailConfig;
2550
2582
  function GenerateId(obj) {
2551
2583
  Object.keys(obj).forEach(function (key) {
2552
2584
  if (key == "_id" && obj[key] == "$id") {
2553
- obj[key] = new mongodb_1.ObjectID();
2585
+ obj[key] = new mongodb_1.ObjectId();
2554
2586
  }
2555
2587
  else if (Array.isArray(obj[key])) {
2556
2588
  for (var i = 0; i < obj[key].length; i++) {
@@ -3906,15 +3938,16 @@ function GetDayIndex(day) {
3906
3938
  }
3907
3939
  exports.GetDayIndex = GetDayIndex;
3908
3940
  function GetUserProfile(msp_d, db, mdb, next) {
3941
+ var _a;
3909
3942
  return __awaiter(this, void 0, void 0, function () {
3910
3943
  var userData, userProfile_1, error_3, objectIDs_1, modules_1, licenceDetail, moduleList, _loop_17, i, error_4;
3911
- return __generator(this, function (_a) {
3912
- switch (_a.label) {
3944
+ return __generator(this, function (_b) {
3945
+ switch (_b.label) {
3913
3946
  case 0:
3914
- _a.trys.push([0, 10, , 11]);
3915
- return [4 /*yield*/, db.collection("User").findOne({ '_id': new mongodb_1.ObjectID(msp_d.ui), IsActive: true }, { projection: { 'LicenceDetail': 1 } })];
3947
+ _b.trys.push([0, 10, , 11]);
3948
+ return [4 /*yield*/, db.collection("User").findOne({ '_id': new mongodb_1.ObjectId(msp_d.ui), IsActive: true }, { projection: { 'LicenceDetail': 1 } })];
3916
3949
  case 1:
3917
- userData = _a.sent();
3950
+ userData = _b.sent();
3918
3951
  if (!userData) {
3919
3952
  return [2 /*return*/, { statusCode: 500, message: "User data not found.", data: {} }];
3920
3953
  }
@@ -3922,11 +3955,11 @@ function GetUserProfile(msp_d, db, mdb, next) {
3922
3955
  return [2 /*return*/, { statusCode: 200, message: "There is no licence assigned to this user, please contact your administrator.", data: {} }];
3923
3956
  }
3924
3957
  userProfile_1 = undefined;
3925
- _a.label = 2;
3958
+ _b.label = 2;
3926
3959
  case 2:
3927
- _a.trys.push([2, 4, , 5]);
3960
+ _b.trys.push([2, 4, , 5]);
3928
3961
  return [4 /*yield*/, db.collection("UserProfile").aggregate([
3929
- { $match: { _id: new mongodb_1.ObjectID(msp_d.upi), IsActive: true } },
3962
+ { $match: { _id: new mongodb_1.ObjectId(msp_d.upi), IsActive: true } },
3930
3963
  {
3931
3964
  $lookup: {
3932
3965
  from: "ModuleMaster",
@@ -3941,10 +3974,10 @@ function GetUserProfile(msp_d, db, mdb, next) {
3941
3974
  { $project: { _id: 1, Name: 1, IsAdmin: 1, UserMenu: 1, Permissions: 1, ModuleList: 1, IsSystemDefine: 1 } },
3942
3975
  ]).toArray()];
3943
3976
  case 3:
3944
- userProfile_1 = _a.sent();
3977
+ userProfile_1 = _b.sent();
3945
3978
  return [3 /*break*/, 5];
3946
3979
  case 4:
3947
- error_3 = _a.sent();
3980
+ error_3 = _b.sent();
3948
3981
  console.log('No Module provided to userprofile');
3949
3982
  return [2 /*return*/, { statusCode: 500, message: "Your profile doesn't have any module access. Please contact your Administrator.", data: {} }];
3950
3983
  case 5:
@@ -3960,7 +3993,7 @@ function GetUserProfile(msp_d, db, mdb, next) {
3960
3993
  modules_1 = [];
3961
3994
  return [4 /*yield*/, mdb.collection("Licences").find({ '_id': { $in: objectIDs_1 }, 'Status': 'active', 'IsActive': true }).toArray()];
3962
3995
  case 7:
3963
- licenceDetail = _a.sent();
3996
+ licenceDetail = _b.sent();
3964
3997
  if (licenceDetail && licenceDetail.length > 0) {
3965
3998
  licenceDetail.forEach(function (licence) {
3966
3999
  modules_1 = modules_1.concat(licence.Modules);
@@ -3972,7 +4005,7 @@ function GetUserProfile(msp_d, db, mdb, next) {
3972
4005
  if (userProfile_1[0].Permissions) {
3973
4006
  _loop_17 = function (i) {
3974
4007
  userProfile_1[0].Permissions[i].ModuleData = moduleList.find(function (x) { return x._id == userProfile_1[0].Permissions[i].ModuleID; });
3975
- if (userProfile_1[0].Permissions[i].Operations.includes("Control Panel")) {
4008
+ if ((_a = userProfile_1[0].Permissions[i].Operations) === null || _a === void 0 ? void 0 : _a.includes("Control Panel")) {
3976
4009
  userProfile_1[0].HasControlPanelAccess.push(userProfile_1[0].Permissions[i].ModuleID);
3977
4010
  }
3978
4011
  };
@@ -3993,7 +4026,7 @@ function GetUserProfile(msp_d, db, mdb, next) {
3993
4026
  case 8: return [2 /*return*/, { statusCode: 200, message: "There is no licence assigned to this user, please contact your administrator.", data: {} }];
3994
4027
  case 9: return [3 /*break*/, 11];
3995
4028
  case 10:
3996
- error_4 = _a.sent();
4029
+ error_4 = _b.sent();
3997
4030
  console.error("Internal Error in GetUserProfile Utility function : " + error_4);
3998
4031
  next(error_4);
3999
4032
  return [3 /*break*/, 11];
@@ -4183,7 +4216,7 @@ function ValidateSanitizeUserInput(inputFields, pageData) {
4183
4216
  if (inputFields.hasOwnProperty(key)) {
4184
4217
  val = inputFields[key];
4185
4218
  //if (val !== null && (typeof val === 'object' || mongodb.ObjectID.isValid(val))) {
4186
- if (val !== null && (typeof val === 'object' || mongodb_1.ObjectID.isValid(val))) {
4219
+ if (val !== null && (typeof val === 'object' || mongodb_1.ObjectId.isValid(val))) {
4187
4220
  inputItem[key] = val;
4188
4221
  }
4189
4222
  else {
@@ -4243,7 +4276,7 @@ function CreateBanquetingVATSettingsData(msp_d, db, sdata, next) {
4243
4276
  switch (_b.label) {
4244
4277
  case 0:
4245
4278
  _b.trys.push([0, 6, , 7]);
4246
- userID = new mongodb_1.ObjectID(msp_d.ui);
4279
+ userID = new mongodb_1.ObjectId(msp_d.ui);
4247
4280
  return [4 /*yield*/, db.collection('ObjectSchema').findOne({ Name: "BanquetingVATSettings" })];
4248
4281
  case 1:
4249
4282
  schemaData = _b.sent();
@@ -4291,7 +4324,7 @@ function CheckReportFolderAccess(report, db, msp_d, folderActiveStatus) {
4291
4324
  switch (_a.label) {
4292
4325
  case 0:
4293
4326
  shareFolderIds = [];
4294
- userID = new mongodb_1.ObjectID(msp_d.ui);
4327
+ userID = new mongodb_1.ObjectId(msp_d.ui);
4295
4328
  FolderList = [];
4296
4329
  return [4 /*yield*/, db.collection('User').findOne({ _id: userID }, { projection: { MySettings: 1 } })];
4297
4330
  case 1:
@@ -569,7 +569,7 @@ var checkForLookupAndListSchema = function (object, key, schema, restoredObject,
569
569
  return __generator(this, function (_a) {
570
570
  switch (_a.label) {
571
571
  case 0:
572
- objectid = mongodb_1.default.ObjectID;
572
+ objectid = mongodb_1.default.ObjectId;
573
573
  if (!(schema.find(function (o) { return o.Name == key && o.LookupFields && o.LookupFields.length > 0; }) && key !== 'Tag')) return [3 /*break*/, 1];
574
574
  objSchema = schema.find(function (o) { return o.Name == key; });
575
575
  schemalookupfieldsDisplayValue_1 = objSchema.LookupFields;
@@ -660,7 +660,7 @@ var checkForLookupAndListSchema = function (object, key, schema, restoredObject,
660
660
  if (!(key == 'CreatedBy' && objectid.isValid(object[key]) || key == 'ModifiedBy' && objectid.isValid(object[key]))) return [3 /*break*/, 11];
661
661
  db = global['dbConnections'][req.DBName];
662
662
  return [4 /*yield*/, db.collection('User').findOne({
663
- _id: new mongodb_1.default.ObjectID(object[key])
663
+ _id: new mongodb_1.default.ObjectId(object[key])
664
664
  })];
665
665
  case 10:
666
666
  UserInfo = _a.sent();
@@ -808,8 +808,8 @@ var mapAttendeToContactAndUser = function (attendee, key, filterdObj, db) {
808
808
  switch (_a.label) {
809
809
  case 0:
810
810
  Users = [];
811
- (attendee.Id) ? Users.push(new mongodb_1.default.ObjectID(attendee.Id)) : '';
812
- (attendee.InvitedBy) ? Users.push(new mongodb_1.default.ObjectID(attendee.InvitedBy)) : '';
811
+ (attendee.Id) ? Users.push(new mongodb_1.default.ObjectId(attendee.Id)) : '';
812
+ (attendee.InvitedBy) ? Users.push(new mongodb_1.default.ObjectId(attendee.InvitedBy)) : '';
813
813
  return [4 /*yield*/, db.collection('ViewAttendee').find({ _id: { $in: Users } }, { projection: { Name: 1 } }).toArray()];
814
814
  case 1:
815
815
  alluserInfo = _a.sent();
@@ -904,7 +904,7 @@ var mapDriveFolderIdToFolderName = function (driveObj, db) {
904
904
  driveObj['FolderName'] = driveObj.FolderId;
905
905
  delete driveObj.FolderId;
906
906
  return [3 /*break*/, 3];
907
- case 1: return [4 /*yield*/, db.collection('Drive').findOne({ _id: new mongodb_1.default.ObjectID(driveObj.FolderId) }, { projection: { FileName: 1, _id: 0 } })];
907
+ case 1: return [4 /*yield*/, db.collection('Drive').findOne({ _id: new mongodb_1.default.ObjectId(driveObj.FolderId) }, { projection: { FileName: 1, _id: 0 } })];
908
908
  case 2:
909
909
  parentFolderName = _a.sent();
910
910
  delete driveObj.FolderId;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@optimiser/common",
3
- "version": "1.0.264",
3
+ "version": "1.0.267",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
@@ -22,12 +22,12 @@
22
22
  "aws-sdk": "^2.786.0",
23
23
  "axios": "^0.21.1",
24
24
  "bson": "^4.2.0",
25
- "exceljs": "^4.2.1",
25
+ "exceljs": "^4.3.0",
26
26
  "express": "^4.17.1",
27
27
  "express-validator": "^6.9.2",
28
28
  "geoip-lite": "^1.4.2",
29
29
  "ioredis": "^4.17.3",
30
- "libphonenumber-js": "^1.9.23",
30
+ "libphonenumber-js": "^1.9.51",
31
31
  "moment": "^2.25.3",
32
32
  "moment-timezone": "^0.5.27",
33
33
  "mongo-sanitize": "^1.1.0",