drapcode-utility 2.6.2 → 2.6.4
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.
|
@@ -326,8 +326,12 @@ const conditionToQuery = (query, requiredExternal, externalParams, constants, ti
|
|
|
326
326
|
const { startValue, endValue, isInteger } = (0, query_utils_1.getMinMaxValue)(fieldValue);
|
|
327
327
|
return {
|
|
328
328
|
[field]: {
|
|
329
|
-
$gte: isInteger
|
|
330
|
-
|
|
329
|
+
$gte: isInteger
|
|
330
|
+
? +startValue
|
|
331
|
+
: prepareBetweenValues(startValue, fieldType),
|
|
332
|
+
$lte: isInteger
|
|
333
|
+
? +endValue
|
|
334
|
+
: prepareBetweenValues(endValue, fieldType),
|
|
331
335
|
},
|
|
332
336
|
};
|
|
333
337
|
}
|
|
@@ -461,7 +465,7 @@ const changeExternalParams = (query, requiredExternal, externalParams, constants
|
|
|
461
465
|
else {
|
|
462
466
|
const resolveValue = (val) => {
|
|
463
467
|
if ([drapcode_constant_1.CURRENT_USER, ...drapcode_constant_1.DateConstant].some((cnst) => val.includes?.(cnst))) {
|
|
464
|
-
return (0, query_utils_1.getValueOfProjectConstant)(val, user, timezone);
|
|
468
|
+
return (0, query_utils_1.getValueOfProjectConstant)(val, user, timezone, fieldType);
|
|
465
469
|
}
|
|
466
470
|
else if (!isFixedValue) {
|
|
467
471
|
const found = constants.find((constant) => constant.name === val);
|
|
@@ -575,3 +579,8 @@ const prepareBooleanQuery = (field, fieldValue) => {
|
|
|
575
579
|
$or: [{ [field]: boolVal }, { [field]: { $exists: false } }],
|
|
576
580
|
};
|
|
577
581
|
};
|
|
582
|
+
const prepareBetweenValues = (value, fieldType) => {
|
|
583
|
+
if (["createdat", "updatedat", ...drapcode_constant_1.systemDateField].includes(fieldType))
|
|
584
|
+
return new Date(value);
|
|
585
|
+
return value;
|
|
586
|
+
};
|
|
@@ -23,7 +23,7 @@ export declare const DATE_REGEX: RegExp;
|
|
|
23
23
|
export declare const createLoggerDateFormat: (timezone?: string) => string;
|
|
24
24
|
export declare const createLoggerPreviousDateFormat: () => string;
|
|
25
25
|
export declare const createLogsDateFormat: (timezone?: string) => string;
|
|
26
|
-
export declare const getDateValue: (value: string, timezone?: string) => string;
|
|
26
|
+
export declare const getDateValue: (value: string, timezone?: string, fieldType?: string) => string;
|
|
27
27
|
export declare const getDateRangeValue: (key: string, field: string, value: string) => DateRangeValue;
|
|
28
28
|
export declare const nextDayDate: (date: string | Date) => string;
|
|
29
29
|
export declare const timezoneDateParse: (value: string, nextDay?: boolean, prevDay?: boolean) => Date;
|
package/build/utils/date-util.js
CHANGED
|
@@ -47,11 +47,11 @@ const createLogsDateFormat = (timezone) => {
|
|
|
47
47
|
}
|
|
48
48
|
};
|
|
49
49
|
exports.createLogsDateFormat = createLogsDateFormat;
|
|
50
|
-
const getDateValue = (value, timezone) => {
|
|
50
|
+
const getDateValue = (value, timezone, fieldType = "datetime-local") => {
|
|
51
51
|
try {
|
|
52
52
|
if (!value)
|
|
53
53
|
return (0, exports.createLogsDateFormat)(timezone);
|
|
54
|
-
const dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
|
|
54
|
+
const dateFormat = fieldType === "date" ? "YYYY-MM-DD" : "YYYY-MM-DDTHH:mm:ss.SSS";
|
|
55
55
|
const [type, number, unit] = value.split(":");
|
|
56
56
|
if (!["ADD", "SUB"].includes(type)) {
|
|
57
57
|
return (0, exports.createLogsDateFormat)(timezone);
|
|
@@ -17,4 +17,4 @@ export declare const getMinMaxValue: (value: any) => {
|
|
|
17
17
|
isInteger?: undefined;
|
|
18
18
|
};
|
|
19
19
|
export declare const isFixedValueQuery: (value: any) => boolean;
|
|
20
|
-
export declare const getValueOfProjectConstant: (value: any, currentUser: any, timezone: string) => any;
|
|
20
|
+
export declare const getValueOfProjectConstant: (value: any, currentUser: any, timezone: string, fieldType?: string) => any;
|
|
@@ -242,7 +242,7 @@ const isFixedValueQuery = (value) => {
|
|
|
242
242
|
return isFixeValue;
|
|
243
243
|
};
|
|
244
244
|
exports.isFixedValueQuery = isFixedValueQuery;
|
|
245
|
-
const getValueOfProjectConstant = (value, currentUser, timezone) => {
|
|
245
|
+
const getValueOfProjectConstant = (value, currentUser, timezone, fieldType = "datetime-local") => {
|
|
246
246
|
if (!timezone)
|
|
247
247
|
timezone = "(GMT+5:30)";
|
|
248
248
|
timezone = timezone.substring(4, 10);
|
|
@@ -254,7 +254,7 @@ const getValueOfProjectConstant = (value, currentUser, timezone) => {
|
|
|
254
254
|
if ([drapcode_constant_1.CURRENT_TIME, drapcode_constant_1.CURRENT_DATE_TIME].includes(value))
|
|
255
255
|
result = (0, date_util_1.createLogsDateFormat)(timezone);
|
|
256
256
|
if (drapcode_constant_1.DateTimeUnit.some((cnst) => value.includes(cnst)))
|
|
257
|
-
result = (0, date_util_1.getDateValue)(value, timezone);
|
|
257
|
+
result = (0, date_util_1.getDateValue)(value, timezone, fieldType);
|
|
258
258
|
return result;
|
|
259
259
|
};
|
|
260
260
|
exports.getValueOfProjectConstant = getValueOfProjectConstant;
|
package/build/utils/util.js
CHANGED
|
@@ -1,4 +1,37 @@
|
|
|
1
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 () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
2
35
|
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
36
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
37
|
};
|
|
@@ -12,7 +45,7 @@ const format_fields_1 = require("../format-fields");
|
|
|
12
45
|
const uuid_1 = require("uuid");
|
|
13
46
|
const voca_1 = __importDefault(require("voca"));
|
|
14
47
|
const numeral_1 = __importDefault(require("numeral"));
|
|
15
|
-
const
|
|
48
|
+
const math = __importStar(require("mathjs"));
|
|
16
49
|
const moment_1 = __importDefault(require("moment"));
|
|
17
50
|
const mime_types_1 = __importDefault(require("mime-types"));
|
|
18
51
|
const uuid_2 = require("uuid");
|
|
@@ -935,7 +968,7 @@ const addition = function (formatType, { numbers }) {
|
|
|
935
968
|
}
|
|
936
969
|
numbers = numbers.map((number) => (isNaN(number) ? 0 : number));
|
|
937
970
|
const allNumbers = (0, exports.validateNumbers)(numbers);
|
|
938
|
-
return (0, numeral_1.default)(
|
|
971
|
+
return (0, numeral_1.default)(math.sum(allNumbers)).format(formatType ? formatType : "00.00");
|
|
939
972
|
}
|
|
940
973
|
catch (err) {
|
|
941
974
|
console.log("🚀 ~ file: util.js:89 ~ addition ~ error:", err);
|
|
@@ -946,12 +979,12 @@ exports.addition = addition;
|
|
|
946
979
|
const substraction = function (formatType, { numbers1, numbers2 }) {
|
|
947
980
|
try {
|
|
948
981
|
const actNumber1 = Array.isArray(numbers1)
|
|
949
|
-
?
|
|
982
|
+
? math.sum(...numbers1)
|
|
950
983
|
: numbers1;
|
|
951
984
|
const actNumber2 = Array.isArray(numbers2)
|
|
952
|
-
?
|
|
985
|
+
? math.sum(...numbers2)
|
|
953
986
|
: numbers2;
|
|
954
|
-
return (0, numeral_1.default)(
|
|
987
|
+
return (0, numeral_1.default)(math.subtract(actNumber1, actNumber2)).format(formatType ? formatType : "00.00");
|
|
955
988
|
}
|
|
956
989
|
catch (err) {
|
|
957
990
|
console.log("🚀 ~ file: util.js:202 ~ substraction ~ error:", err);
|
|
@@ -966,7 +999,7 @@ const average = function (formatType, { numbers }) {
|
|
|
966
999
|
}
|
|
967
1000
|
numbers = numbers.map((number) => (isNaN(number) ? 0 : number));
|
|
968
1001
|
const allNumbers = (0, exports.validateNumbers)(numbers);
|
|
969
|
-
return (0, numeral_1.default)(
|
|
1002
|
+
return (0, numeral_1.default)(math.mean(...allNumbers)).format(formatType ? formatType : "00.00");
|
|
970
1003
|
}
|
|
971
1004
|
catch (err) {
|
|
972
1005
|
console.log("🚀 ~ file: util.js:98 ~ average ~ error:", err);
|
|
@@ -981,7 +1014,7 @@ const multiply = function (formatType, { numbers }) {
|
|
|
981
1014
|
}
|
|
982
1015
|
numbers = numbers.map((number) => (isNaN(number) ? 1 : number));
|
|
983
1016
|
const allNumbers = (0, exports.validateNumbers)(numbers);
|
|
984
|
-
return (0, numeral_1.default)(
|
|
1017
|
+
return (0, numeral_1.default)(math.prod(...allNumbers)).format(formatType ? formatType : "00.00");
|
|
985
1018
|
}
|
|
986
1019
|
catch (err) {
|
|
987
1020
|
console.log("🚀 ~ file: util.js:106 ~ multiply ~ error:", err);
|
|
@@ -993,7 +1026,7 @@ const divide = function (formatType, { number1, number2 }) {
|
|
|
993
1026
|
try {
|
|
994
1027
|
const num1 = (0, exports.checkAndConvertNumber)(number1);
|
|
995
1028
|
const num2 = (0, exports.checkAndConvertNumber)(number2);
|
|
996
|
-
return (0, numeral_1.default)(
|
|
1029
|
+
return (0, numeral_1.default)(math.divide(num1, num2)).format(formatType ? formatType : "00.00");
|
|
997
1030
|
}
|
|
998
1031
|
catch (err) {
|
|
999
1032
|
console.log("🚀 ~ file: util.js:114 ~ divide ~ error:", err);
|
|
@@ -1007,7 +1040,7 @@ const evaluateExpression = function (expression, data, user, formatType, envCons
|
|
|
1007
1040
|
: " ";
|
|
1008
1041
|
const replacedExpression = (0, exports.replaceDataValueIntoExpression)(expression, data, user, {}, {}, {}, {}, envConstants, {}, {}, {});
|
|
1009
1042
|
try {
|
|
1010
|
-
return (0, numeral_1.default)(
|
|
1043
|
+
return (0, numeral_1.default)(math.evaluate(replacedExpression)).format(formatType ? formatType : "00.00");
|
|
1011
1044
|
}
|
|
1012
1045
|
catch (err) {
|
|
1013
1046
|
return "";
|