drapcode-utility 2.7.0 → 2.7.2

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.
@@ -231,7 +231,7 @@ const conditionToQuery = (query, requiredExternal, externalParams, constants, ti
231
231
  if ([drapcode_constant_1.NOT_EQUAL, ...isEqualOrIgnore].includes(key) &&
232
232
  typeof value === "string" &&
233
233
  drapcode_constant_1.DateRangeConstant.some((cnst) => value.includes(cnst))) {
234
- let final = (0, date_util_1.getDateRangeValue)(key, field, value);
234
+ let final = (0, date_util_1.getDateRangeValue)(key, field, value, fieldType);
235
235
  return final;
236
236
  }
237
237
  console.log("No date range constants");
@@ -6,16 +6,16 @@ interface DateField {
6
6
  type: string;
7
7
  extraFieldSetting?: Map<string, ExtraFieldSetting>;
8
8
  }
9
+ interface DateComparison {
10
+ $gte?: string | Date;
11
+ $lte?: string | Date;
12
+ $lt?: string | Date;
13
+ $gt?: string | Date;
14
+ }
9
15
  interface DateRangeValue {
10
- [key: string]: {
11
- $gte?: string;
12
- $lte?: string;
13
- } | {
16
+ [key: string]: DateComparison | {
14
17
  $or?: Array<{
15
- [key: string]: {
16
- $gte?: string;
17
- $lte?: string;
18
- };
18
+ [key: string]: DateComparison;
19
19
  }>;
20
20
  };
21
21
  }
@@ -24,7 +24,7 @@ export declare const createLoggerDateFormat: (timezone?: string) => string;
24
24
  export declare const createLoggerPreviousDateFormat: () => string;
25
25
  export declare const createLogsDateFormat: (timezone?: string) => string;
26
26
  export declare const getDateValue: (value: string, timezone?: string, fieldType?: string) => string;
27
- export declare const getDateRangeValue: (key: string, field: string, value: string) => DateRangeValue;
27
+ export declare const getDateRangeValue: (key: string, field: string, value: string, fieldType?: string) => DateRangeValue;
28
28
  export declare const nextDayDate: (date: string | Date) => string;
29
29
  export declare const timezoneDateParse: (value: string, nextDay?: boolean, prevDay?: boolean, isDateTime?: any) => any;
30
30
  export declare const formatProjectDates: (item: Record<string, any> | Record<string, any>[], dateFormat: string, fields: DateField[], reverse: boolean) => Record<string, any> | Record<string, any>[];
@@ -7,7 +7,6 @@ exports.formatProjectDates = exports.timezoneDateParse = exports.nextDayDate = e
7
7
  const drapcode_constant_1 = require("drapcode-constant");
8
8
  const lodash_1 = __importDefault(require("lodash"));
9
9
  const moment_1 = __importDefault(require("moment"));
10
- const dateFormat = "YYYY-MM-DDTHH:mm:ss.SSS";
11
10
  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})?)?$/;
12
11
  const createLoggerDateFormat = (timezone) => {
13
12
  try {
@@ -81,7 +80,7 @@ const getDateValue = (value, timezone, fieldType = "datetime-local") => {
81
80
  }
82
81
  };
83
82
  exports.getDateValue = getDateValue;
84
- const getDateRangeValue = (key, field, value) => {
83
+ const getDateRangeValue = (key, field, value, fieldType = "datetime-local") => {
85
84
  try {
86
85
  let startValue = null;
87
86
  let endValue = null;
@@ -94,19 +93,23 @@ const getDateRangeValue = (key, field, value) => {
94
93
  startValue = (0, moment_1.default)().startOf("year");
95
94
  endValue = (0, moment_1.default)().endOf("year");
96
95
  break;
96
+ case drapcode_constant_1.CURRENT_WEEK:
97
+ startValue = (0, moment_1.default)().startOf("isoWeek");
98
+ endValue = (0, moment_1.default)().endOf("isoWeek");
99
+ break;
97
100
  default:
98
101
  return {};
99
102
  }
100
103
  if (!startValue || !endValue) {
101
104
  return {};
102
105
  }
103
- startValue = formatDate(startValue);
104
- endValue = formatDate(endValue);
106
+ startValue = getDateValueForQuery(field, fieldType, startValue);
107
+ endValue = getDateValueForQuery(field, fieldType, endValue);
105
108
  if ([drapcode_constant_1.EQUALS, drapcode_constant_1.EQUALS_OR_IGNORE].includes(key)) {
106
109
  return {
107
110
  [field]: {
108
111
  $gte: startValue,
109
- $lte: endValue,
112
+ $lt: endValue,
110
113
  },
111
114
  };
112
115
  }
@@ -114,7 +117,7 @@ const getDateRangeValue = (key, field, value) => {
114
117
  return {
115
118
  $or: [
116
119
  { [field]: { $gte: endValue } },
117
- { [field]: { $lte: startValue } },
120
+ { [field]: { $lt: startValue } },
118
121
  ],
119
122
  };
120
123
  }
@@ -126,10 +129,16 @@ const getDateRangeValue = (key, field, value) => {
126
129
  }
127
130
  };
128
131
  exports.getDateRangeValue = getDateRangeValue;
129
- const formatDate = (date) => {
130
- if (!date)
131
- return `${date}`;
132
- return date.format(dateFormat);
132
+ const getDateValueForQuery = (field, fieldType, value) => {
133
+ if (!value)
134
+ return `${value}`;
135
+ if (["createdAt", "updatedAt"].includes(field)) {
136
+ return value.toDate();
137
+ }
138
+ if (fieldType === "date") {
139
+ return value.format("YYYY-MM-DD");
140
+ }
141
+ return value.format("YYYY-MM-DDTHH:mm:ss");
133
142
  };
134
143
  const getDateUnit = (unit) => {
135
144
  switch (unit) {
@@ -207,7 +216,7 @@ const formatItemDates = (item, fields, dateFormat, reverse) => {
207
216
  }
208
217
  if (dateDisplayType === "datetime-local") {
209
218
  item[fieldName] = (0, moment_1.default)(item[fieldName], dateTimeFormat).isValid()
210
- ? item[fieldName]
219
+ ? (0, moment_1.default)(item[fieldName]).format("YYYY-MM-DDTHH:mm:ss")
211
220
  : "";
212
221
  }
213
222
  else {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "drapcode-utility",
3
- "version": "2.7.0",
3
+ "version": "2.7.2",
4
4
  "description": "DrapCode Utility",
5
5
  "main": "build/index.js",
6
6
  "types": "build/index.d.ts",
@@ -42,9 +42,9 @@
42
42
  "axios": "^1.1.2",
43
43
  "date-fns": "^4.1.0",
44
44
  "dompurify": "^3.1.7",
45
- "drapcode-constant": "^2.0.8",
45
+ "drapcode-constant": "^2.0.9",
46
46
  "drapcode-logger": "^1.3.6",
47
- "drapcode-redis": "^1.5.5",
47
+ "drapcode-redis": "^1.5.6",
48
48
  "exiftool-vendored": "^28.2.1",
49
49
  "express": "^4.17.1",
50
50
  "gm": "^1.25.0",