drapcode-utility 1.7.1 → 1.7.3
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.js
CHANGED
|
@@ -688,8 +688,10 @@ var validateData = function (fields, data) {
|
|
|
688
688
|
}
|
|
689
689
|
break;
|
|
690
690
|
case "tel":
|
|
691
|
-
var
|
|
692
|
-
|
|
691
|
+
var removedSpace = fieldValue.replace(/\s+/g, "");
|
|
692
|
+
var telPattern = /^\+?(\d{1,3})?[-]?(\(\d{1,4}\)|\d{1,4})[-]?(\d{1,4}[-]?\d{1,4}|\d{7,10})$/;
|
|
693
|
+
if (typeof removedSpace !== "string" ||
|
|
694
|
+
!telPattern.test(removedSpace)) {
|
|
693
695
|
errors.push("".concat(fieldTitle, " must be a valid phone number"));
|
|
694
696
|
}
|
|
695
697
|
break;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "drapcode-utility",
|
|
3
|
-
"version": "1.7.
|
|
3
|
+
"version": "1.7.3",
|
|
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",
|