drapcode-utility 1.7.2 → 1.7.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.
|
@@ -3,6 +3,7 @@ export declare const createLoggerDateFormat: (timezone?: string) => any;
|
|
|
3
3
|
export declare const createLoggerPreviouseDateFormat: () => any;
|
|
4
4
|
export declare const createLogsDateFormat: (timezone?: string) => any;
|
|
5
5
|
export declare const getDateValue: (value: string, timezone?: string) => any;
|
|
6
|
+
export declare const getDateRangeValue: (key: string, field: string, value: string) => any;
|
|
6
7
|
export declare const nextDayDate: (date: any) => any;
|
|
7
8
|
export declare const timezoneDateParse: (value: string, nextDay?: boolean, prevDay?: boolean) => Date;
|
|
8
9
|
export declare const formatProjectDates: (item: any, dateFormat: string, fields: Array<object>, reverse: boolean) => any;
|
package/build/utils/date-util.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.formatProjectDates = exports.timezoneDateParse = exports.nextDayDate = exports.getDateValue = exports.createLogsDateFormat = exports.createLoggerPreviouseDateFormat = exports.createLoggerDateFormat = exports.DATE_REGEX = void 0;
|
|
3
|
+
exports.formatProjectDates = exports.timezoneDateParse = exports.nextDayDate = exports.getDateRangeValue = exports.getDateValue = exports.createLogsDateFormat = exports.createLoggerPreviouseDateFormat = exports.createLoggerDateFormat = exports.DATE_REGEX = void 0;
|
|
4
4
|
var drapcode_constant_1 = require("drapcode-constant");
|
|
5
5
|
var moment = require("moment");
|
|
6
6
|
exports.DATE_REGEX = /^[12]\d{3}(-(0[1-9]|1[0-2])(-(0[1-9]|[12][0-9]|3[01]))?)(T| )?(([01][0-9]|2[0-3]):[0-5]\d(:[0-5]\d(\.\d+)?)?(Z|[+-]\d{2}:\d{2})?)?$/;
|
|
@@ -46,6 +46,47 @@ var getDateValue = function (value, timezone) {
|
|
|
46
46
|
return result.format(dateFormat);
|
|
47
47
|
};
|
|
48
48
|
exports.getDateValue = getDateValue;
|
|
49
|
+
var getDateRangeValue = function (key, field, value) {
|
|
50
|
+
var _a, _b, _c;
|
|
51
|
+
var dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
|
|
52
|
+
var finalValue = "";
|
|
53
|
+
var startValue = "";
|
|
54
|
+
var endValue = "";
|
|
55
|
+
switch (value) {
|
|
56
|
+
case drapcode_constant_1.CURRENT_MONTH:
|
|
57
|
+
// Start of the current month
|
|
58
|
+
startValue = moment().startOf("month");
|
|
59
|
+
// End of the current month
|
|
60
|
+
endValue = moment().endOf("month");
|
|
61
|
+
break;
|
|
62
|
+
case drapcode_constant_1.CURRENT_YEAR:
|
|
63
|
+
// Start of the current year
|
|
64
|
+
startValue = moment().startOf("year");
|
|
65
|
+
// End of the current year
|
|
66
|
+
endValue = moment().endOf("year");
|
|
67
|
+
break;
|
|
68
|
+
default:
|
|
69
|
+
break;
|
|
70
|
+
}
|
|
71
|
+
if (key === drapcode_constant_1.EQUALS) {
|
|
72
|
+
finalValue = (_a = {},
|
|
73
|
+
_a[field] = {
|
|
74
|
+
$gte: startValue.format(dateFormat),
|
|
75
|
+
$lte: endValue.format(dateFormat),
|
|
76
|
+
},
|
|
77
|
+
_a);
|
|
78
|
+
}
|
|
79
|
+
else if (key === drapcode_constant_1.NOT_EQUAL) {
|
|
80
|
+
finalValue = {
|
|
81
|
+
$or: [
|
|
82
|
+
(_b = {}, _b[field] = { $gte: endValue.format(dateFormat) }, _b),
|
|
83
|
+
(_c = {}, _c[field] = { $lte: startValue.format(dateFormat) }, _c),
|
|
84
|
+
],
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
return finalValue;
|
|
88
|
+
};
|
|
89
|
+
exports.getDateRangeValue = getDateRangeValue;
|
|
49
90
|
var getDateUnit = function (unit) {
|
|
50
91
|
switch (unit) {
|
|
51
92
|
case drapcode_constant_1.HOUR:
|
|
@@ -276,6 +276,13 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
276
276
|
if (currentUser === void 0) { currentUser = {}; }
|
|
277
277
|
if (currentTenant === void 0) { currentTenant = {}; }
|
|
278
278
|
if (currentUserSetting === void 0) { currentUserSetting = {}; }
|
|
279
|
+
var key = query.key, field = query.field, value = query.value, fieldType = query.fieldType;
|
|
280
|
+
if ([drapcode_constant_1.EQUALS, drapcode_constant_1.NOT_EQUAL].includes(key) &&
|
|
281
|
+
drapcode_constant_1.DateRangeConstant.some(function (cnst) { return value.includes(cnst); })) {
|
|
282
|
+
var final = (0, date_util_1.getDateRangeValue)(key, field, value);
|
|
283
|
+
console.log("\n ===final getDateRangeValue", final);
|
|
284
|
+
return final;
|
|
285
|
+
}
|
|
279
286
|
var fieldValue = replaceExternalParams(query, requiredExternal, externalParams, constants, currentUser, currentTenant, currentUserSetting, timezone);
|
|
280
287
|
if (["undefined", "null", null, undefined, ""].includes(fieldValue)) {
|
|
281
288
|
//TODO: In case field is not present in old record then fieldValue is undefined
|
|
@@ -287,7 +294,6 @@ var queryToMongo = function (query, requiredExternal, externalParams, constants,
|
|
|
287
294
|
console.log("fieldValue queryToMongo 1", fieldValue);
|
|
288
295
|
var isDate = checkDate(fieldValue);
|
|
289
296
|
console.log("isDate queryToMongo 2", isDate);
|
|
290
|
-
var key = query.key, field = query.field, value = query.value, fieldType = query.fieldType;
|
|
291
297
|
// Todo: Remove if it's working properly
|
|
292
298
|
// if (isDate) fieldValue = new Date(fieldValue);
|
|
293
299
|
console.log("fieldValue queryToMongo 1", fieldValue);
|
package/build/utils/util.d.ts
CHANGED
package/build/utils/util.js
CHANGED
|
@@ -34,7 +34,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
34
34
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
35
35
|
};
|
|
36
36
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
37
|
-
exports.validateUrl = exports.validateData = exports.fillDefaultValues = exports.replaceValueFromSource = exports.processFieldsInlcude = exports.removeMongoDbId = exports.replaceTransferObjectValueIntoExpression = exports.unflattenObject = exports.parseValueFromData = exports.parseJsonString = exports.replaceDataValueIntoExpression = exports.formatCustomCSSClasses = exports.validateAlphanumericString = exports.convertItemToArray = exports.arraysEqual = exports.checkAndCompareValue = exports.restructureData = exports.formatCollectionAndFieldName = exports.cleanCollectionAndFieldName = exports.stringToExpression = exports.expressionToString = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.snakeCaseToTitleCase = exports.dynamicSort = exports.checkValidArray = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = void 0;
|
|
37
|
+
exports.toggleConsoleLogs = exports.validateUrl = exports.validateData = exports.fillDefaultValues = exports.replaceValueFromSource = exports.processFieldsInlcude = exports.removeMongoDbId = exports.replaceTransferObjectValueIntoExpression = exports.unflattenObject = exports.parseValueFromData = exports.parseJsonString = exports.replaceDataValueIntoExpression = exports.formatCustomCSSClasses = exports.validateAlphanumericString = exports.convertItemToArray = exports.arraysEqual = exports.checkAndCompareValue = exports.restructureData = exports.formatCollectionAndFieldName = exports.cleanCollectionAndFieldName = exports.stringToExpression = exports.expressionToString = exports.getSpecialCharectorReplacedExpression = exports.validateUuidString = exports.validateEmail = exports.snakeCaseToTitleCase = exports.dynamicSort = exports.checkValidArray = exports.isObject = exports.isEmptyObject = exports.isEmpty = exports.clearSpaceAndReformat = exports.camelize = exports.validateString = void 0;
|
|
38
38
|
var drapcode_constant_1 = require("drapcode-constant");
|
|
39
39
|
var lodash_1 = __importDefault(require("lodash"));
|
|
40
40
|
var format_fields_1 = require("../format-fields");
|
|
@@ -70,6 +70,9 @@ var derivedFieldExcludes = [
|
|
|
70
70
|
];
|
|
71
71
|
var environmentFixKey = "environment_variable.";
|
|
72
72
|
var tenantFixKey = "current_tenant.";
|
|
73
|
+
var CONSOLE_LOG_MODIFIED = false;
|
|
74
|
+
var OLD_CONSOLE_LOG = null;
|
|
75
|
+
var OLD_CONSOLE_INFO = null;
|
|
73
76
|
var validateString = function (str) {
|
|
74
77
|
var specialChar = /[`!@#$%^&*()_+\-=\[\]{};':"\\|,.<>\/?~]/;
|
|
75
78
|
var isNumber = str.match(/\d+/g);
|
|
@@ -688,8 +691,10 @@ var validateData = function (fields, data) {
|
|
|
688
691
|
}
|
|
689
692
|
break;
|
|
690
693
|
case "tel":
|
|
691
|
-
var
|
|
692
|
-
|
|
694
|
+
var removedSpace = fieldValue.replace(/\s+/g, "");
|
|
695
|
+
var telPattern = /^\+?(\d{1,3})?[-]?(\(\d{1,4}\)|\d{1,4})[-]?(\d{1,4}[-]?\d{1,4}|\d{7,10})$/;
|
|
696
|
+
if (typeof removedSpace !== "string" ||
|
|
697
|
+
!telPattern.test(removedSpace)) {
|
|
693
698
|
errors.push("".concat(fieldTitle, " must be a valid phone number"));
|
|
694
699
|
}
|
|
695
700
|
break;
|
|
@@ -755,3 +760,24 @@ var validateUrl = function (url) {
|
|
|
755
760
|
return !!pattern.test(url);
|
|
756
761
|
};
|
|
757
762
|
exports.validateUrl = validateUrl;
|
|
763
|
+
var toggleConsoleLogs = function (enable) {
|
|
764
|
+
if (enable && CONSOLE_LOG_MODIFIED) {
|
|
765
|
+
console.log('==> Enabling console log|info...');
|
|
766
|
+
if (OLD_CONSOLE_LOG && OLD_CONSOLE_INFO) {
|
|
767
|
+
console.log = OLD_CONSOLE_LOG;
|
|
768
|
+
console.info = OLD_CONSOLE_INFO;
|
|
769
|
+
CONSOLE_LOG_MODIFIED = false;
|
|
770
|
+
console.log("==> Enabling Console log modified: ".concat(CONSOLE_LOG_MODIFIED));
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
else if (!enable && !CONSOLE_LOG_MODIFIED) {
|
|
774
|
+
OLD_CONSOLE_LOG = console.log;
|
|
775
|
+
OLD_CONSOLE_INFO = console.info;
|
|
776
|
+
console.log('==> Disabling console log|info...');
|
|
777
|
+
console.log = function () { };
|
|
778
|
+
console.info = function () { };
|
|
779
|
+
CONSOLE_LOG_MODIFIED = true;
|
|
780
|
+
console.log("==> Disabling Console log modified: ".concat(CONSOLE_LOG_MODIFIED));
|
|
781
|
+
}
|
|
782
|
+
};
|
|
783
|
+
exports.toggleConsoleLogs = toggleConsoleLogs;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.4",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -37,9 +37,9 @@
|
|
|
37
37
|
"@types/voca": "^1.4.2",
|
|
38
38
|
"axios": "^1.1.2",
|
|
39
39
|
"dompurify": "^3.1.7",
|
|
40
|
-
"drapcode-constant": "^1.5.
|
|
41
|
-
"drapcode-logger": "^1.2.
|
|
42
|
-
"drapcode-redis": "^1.1.
|
|
40
|
+
"drapcode-constant": "^1.5.9",
|
|
41
|
+
"drapcode-logger": "^1.2.6",
|
|
42
|
+
"drapcode-redis": "^1.1.5",
|
|
43
43
|
"exiftool-vendored": "^28.2.1",
|
|
44
44
|
"express": "^4.17.1",
|
|
45
45
|
"gm": "^1.25.0",
|