drapcode-utility 1.7.8 → 1.7.9

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,11 +1,14 @@
1
1
  export declare const queryParser: (collectionName: string, query: any, constants: any[], externalParams: any, currentUser: any, timezone: string, searchObj: any, refCollectionFieldsInItems: any, searchQueryTypeObj: any, currentTenant: any, currentUserSetting: any, lookupConfig: any, rowLevelSecurityFilter: any) => Promise<string>;
2
2
  export declare const isEntityInCondition: (value: any) => boolean;
3
+ export declare const isFixedValueQuery: (value: any) => boolean;
3
4
  export declare const getMinMaxValue: (value: any) => {
4
5
  startValue: any;
5
6
  endValue: any;
6
7
  isInteger: any;
8
+ isFixedValue: boolean;
7
9
  } | {
8
10
  startValue: string;
9
11
  endValue: string;
12
+ isFixedValue: boolean;
10
13
  isInteger?: undefined;
11
14
  };
@@ -48,7 +48,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
48
48
  return (mod && mod.__esModule) ? mod : { "default": mod };
49
49
  };
50
50
  Object.defineProperty(exports, "__esModule", { value: true });
51
- exports.getMinMaxValue = exports.isEntityInCondition = exports.queryParser = void 0;
51
+ exports.getMinMaxValue = exports.isFixedValueQuery = exports.isEntityInCondition = exports.queryParser = void 0;
52
52
  var moment_1 = __importDefault(require("moment"));
53
53
  var drapcode_constant_1 = require("drapcode-constant");
54
54
  var date_util_1 = require("./date-util");
@@ -272,7 +272,7 @@ var modifyQuery = function (obj, hasAndQueryConjunction) {
272
272
  return arr;
273
273
  };
274
274
  var queryToMongo = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone) {
275
- var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1;
275
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2;
276
276
  if (currentUser === void 0) { currentUser = {}; }
277
277
  if (currentTenant === void 0) { currentTenant = {}; }
278
278
  if (currentUserSetting === void 0) { currentUserSetting = {}; }
@@ -407,21 +407,25 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
407
407
  return _z = {}, _z[field] = "".concat(fieldValue), _z;
408
408
  }
409
409
  if (key == drapcode_constant_1.NOT_EQUAL)
410
- return _0 = {},
411
- _0[field] = {
412
- $ne: fieldType === "boolean" && fieldValue
413
- ? JSON.parse(fieldValue)
414
- : fieldValue,
415
- },
416
- _0;
410
+ if (fieldType === "number") {
411
+ return _0 = {}, _0[field] = { $ne: +fieldValue }, _0;
412
+ }
413
+ else
414
+ return _1 = {},
415
+ _1[field] = {
416
+ $ne: fieldType === "boolean" && fieldValue
417
+ ? JSON.parse(fieldValue)
418
+ : fieldValue,
419
+ },
420
+ _1;
417
421
  if (key == drapcode_constant_1.BETWEEN) {
418
- var _2 = (0, exports.getMinMaxValue)(fieldValue), startValue = _2.startValue, endValue = _2.endValue, isInteger = _2.isInteger;
419
- return _1 = {},
420
- _1[field] = {
422
+ var _3 = (0, exports.getMinMaxValue)(fieldValue), startValue = _3.startValue, endValue = _3.endValue, isInteger = _3.isInteger;
423
+ return _2 = {},
424
+ _2[field] = {
421
425
  $gte: isInteger ? +startValue : startValue,
422
426
  $lte: isInteger ? +endValue : endValue,
423
427
  },
424
- _1;
428
+ _2;
425
429
  }
426
430
  };
427
431
  var isEntityInCondition = function (value) {
@@ -439,6 +443,22 @@ var isEntityInCondition = function (value) {
439
443
  return isEntity;
440
444
  };
441
445
  exports.isEntityInCondition = isEntityInCondition;
446
+ // TODO: can be refactor with entity condition
447
+ var isFixedValueQuery = function (value) {
448
+ var isFixeValue = false;
449
+ if (value && Array.isArray(value)) {
450
+ value.forEach(function (val) {
451
+ if (typeof val === "string" || val instanceof String)
452
+ isFixeValue = val.startsWith("FIXED_VALUE::");
453
+ });
454
+ }
455
+ else {
456
+ if (value && (typeof value === "string" || value instanceof String))
457
+ isFixeValue = value.startsWith("FIXED_VALUE::");
458
+ }
459
+ return isFixeValue;
460
+ };
461
+ exports.isFixedValueQuery = isFixedValueQuery;
442
462
  var replaceExternalParams = function (query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone) {
443
463
  var key = query.key, value = query.value, fieldType = query.fieldType;
444
464
  if (fieldType &&
@@ -503,7 +523,7 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
503
523
  return valueList_1;
504
524
  }
505
525
  if (key === drapcode_constant_1.BETWEEN) {
506
- var _a = (0, exports.getMinMaxValue)(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger;
526
+ var _a = (0, exports.getMinMaxValue)(value), startValue_1 = _a.startValue, endValue_1 = _a.endValue, isInteger = _a.isInteger, isFixedValue = _a.isFixedValue;
507
527
  if (requiredExternal) {
508
528
  startValue_1 = "".concat(externalParams[startValue_1]);
509
529
  endValue_1 = "".concat(externalParams[endValue_1]);
@@ -514,13 +534,13 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
514
534
  })) {
515
535
  startValue_1 = getValueOfProjectConstant(startValue_1, currentUser, timezone);
516
536
  }
517
- else {
537
+ else if (!isFixedValue) {
518
538
  startValue_1 = constants.filter(function (constant) { return constant.name == startValue_1; });
519
539
  }
520
540
  if (__spreadArray([drapcode_constant_1.CURRENT_USER], drapcode_constant_1.DateConstant, true).some(function (cnst) { return endValue_1.includes(cnst); })) {
521
541
  endValue_1 = getValueOfProjectConstant(endValue_1, currentUser, timezone);
522
542
  }
523
- else {
543
+ else if (!isFixedValue) {
524
544
  endValue_1 = constants.filter(function (constant) { return constant.name == endValue_1; });
525
545
  }
526
546
  }
@@ -557,6 +577,8 @@ var replaceExternalParams = function (query, requiredExternal, externalParams, c
557
577
  var key_1 = value.replace("ENTITY::", "");
558
578
  return externalParams[key_1] ? externalParams[key_1] : "";
559
579
  }
580
+ if ((0, exports.isFixedValueQuery)(value))
581
+ return value.replace("FIXED_VALUE::", "");
560
582
  //TODO: This is just to confirm if external then it should be get from externalParams
561
583
  if (requiredExternal) {
562
584
  //TODO: Value returns from here undefined.
@@ -573,6 +595,9 @@ var checkDate = function (queryValue) {
573
595
  return ("" + queryValue).match(date_util_1.DATE_REGEX);
574
596
  };
575
597
  var getMinMaxValue = function (value) {
598
+ var isFixedValue = (0, exports.isFixedValueQuery)(value);
599
+ if (isFixedValue)
600
+ value = value.replace("FIXED_VALUE::", "");
576
601
  var isValid = value && value.includes("---");
577
602
  if (isValid) {
578
603
  var isInteger = value.includes("^");
@@ -580,10 +605,10 @@ var getMinMaxValue = function (value) {
580
605
  var endValue = result[1];
581
606
  if (isInteger && result.length)
582
607
  endValue = endValue.slice(0, -1);
583
- return { startValue: result[0], endValue: endValue, isInteger: isInteger };
608
+ return { startValue: result[0], endValue: endValue, isInteger: isInteger, isFixedValue: isFixedValue };
584
609
  }
585
610
  else {
586
- return { startValue: "", endValue: "" };
611
+ return { startValue: "", endValue: "", isFixedValue: isFixedValue };
587
612
  }
588
613
  };
589
614
  exports.getMinMaxValue = getMinMaxValue;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "1.7.8",
3
+ "version": "1.7.9",
4
4
  "description": "",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",