@ministryofjustice/hmpps-digital-prison-reporting-frontend 3.26.13 → 3.26.14
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.
|
@@ -5,6 +5,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.setDurationStartAndEnd = exports.updateStore = exports.getRelativeDateOptions = exports.calcDates = void 0;
|
|
7
7
|
const dayjs_1 = __importDefault(require("dayjs"));
|
|
8
|
+
const customParseFormat_1 = __importDefault(require("dayjs/plugin/customParseFormat"));
|
|
8
9
|
const isBetween_1 = __importDefault(require("dayjs/plugin/isBetween"));
|
|
9
10
|
const utils_1 = __importDefault(require("../filters/utils"));
|
|
10
11
|
const enum_1 = require("../filter-input/enum");
|
|
@@ -261,7 +262,10 @@ const setQuerySummary = (req, fields) => {
|
|
|
261
262
|
let querySummary = [];
|
|
262
263
|
const sortData = {};
|
|
263
264
|
// eslint-disable-next-line no-useless-escape
|
|
264
|
-
const
|
|
265
|
+
const isoDateRegEx = /^(\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01]))$/;
|
|
266
|
+
// eslint-disable-next-line no-useless-escape
|
|
267
|
+
const localDateRegEx = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/;
|
|
268
|
+
dayjs_1.default.extend(customParseFormat_1.default);
|
|
265
269
|
Object.keys(req.body)
|
|
266
270
|
.filter((name) => name !== '_csrf' && req.body[name] !== '')
|
|
267
271
|
.forEach((name) => {
|
|
@@ -275,7 +279,13 @@ const setQuerySummary = (req, fields) => {
|
|
|
275
279
|
query[name] = value;
|
|
276
280
|
filterData[shortName] = value;
|
|
277
281
|
let dateDisplayValue;
|
|
278
|
-
if (value.match(
|
|
282
|
+
if (value.match(localDateRegEx)) {
|
|
283
|
+
const formatDate = (0, dayjs_1.default)(value, 'DD/MM/YYYY');
|
|
284
|
+
const isoFormatDate = formatDate.format('YYYY-MM-DD');
|
|
285
|
+
query[name] = isoFormatDate;
|
|
286
|
+
filterData[shortName] = isoFormatDate;
|
|
287
|
+
}
|
|
288
|
+
else if (value.match(isoDateRegEx)) {
|
|
279
289
|
dateDisplayValue = (0, dayjs_1.default)(value).format('DD/MM/YYYY');
|
|
280
290
|
}
|
|
281
291
|
const fieldDisplayName = definitionUtils_1.default.getFieldDisplayName(fields, shortName);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
/* eslint-disable no-param-reassign */
|
|
2
2
|
import { Request, Response } from 'express'
|
|
3
3
|
import dayjs from 'dayjs'
|
|
4
|
+
import customParseFormat from 'dayjs/plugin/customParseFormat'
|
|
4
5
|
import isBetween from 'dayjs/plugin/isBetween'
|
|
5
6
|
import Dict = NodeJS.Dict
|
|
6
7
|
import { components } from '../../types/api'
|
|
@@ -318,7 +319,10 @@ const setQuerySummary = (req: Request, fields: components['schemas']['FieldDefin
|
|
|
318
319
|
let querySummary: Array<Dict<string>> = []
|
|
319
320
|
const sortData: Dict<string> = {}
|
|
320
321
|
// eslint-disable-next-line no-useless-escape
|
|
321
|
-
const
|
|
322
|
+
const isoDateRegEx = /^(\d{4}[\/\-](0?[1-9]|1[012])[\/\-](0?[1-9]|[12][0-9]|3[01]))$/
|
|
323
|
+
// eslint-disable-next-line no-useless-escape
|
|
324
|
+
const localDateRegEx = /^(0?[1-9]|[12][0-9]|3[01])[\/\-](0?[1-9]|1[012])[\/\-]\d{4}$/
|
|
325
|
+
dayjs.extend(customParseFormat)
|
|
322
326
|
|
|
323
327
|
Object.keys(req.body)
|
|
324
328
|
.filter((name) => name !== '_csrf' && req.body[name] !== '')
|
|
@@ -342,9 +346,15 @@ const setQuerySummary = (req: Request, fields: components['schemas']['FieldDefin
|
|
|
342
346
|
filterData[shortName as keyof Dict<string>] = value
|
|
343
347
|
|
|
344
348
|
let dateDisplayValue
|
|
345
|
-
if (value.match(
|
|
349
|
+
if (value.match(localDateRegEx)) {
|
|
350
|
+
const formatDate = dayjs(value, 'DD/MM/YYYY')
|
|
351
|
+
const isoFormatDate = formatDate.format('YYYY-MM-DD')
|
|
352
|
+
query[name as keyof Dict<string>] = isoFormatDate
|
|
353
|
+
filterData[shortName as keyof Dict<string>] = isoFormatDate
|
|
354
|
+
} else if (value.match(isoDateRegEx)) {
|
|
346
355
|
dateDisplayValue = dayjs(value).format('DD/MM/YYYY')
|
|
347
356
|
}
|
|
357
|
+
|
|
348
358
|
const fieldDisplayName = DefinitionUtils.getFieldDisplayName(fields, shortName)
|
|
349
359
|
querySummary.push({
|
|
350
360
|
name: fieldDisplayName || shortName,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ministryofjustice/hmpps-digital-prison-reporting-frontend",
|
|
3
3
|
"description": "The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.",
|
|
4
|
-
"version": "3.26.
|
|
4
|
+
"version": "3.26.14",
|
|
5
5
|
"main": "dpr/assets/js/all.mjs",
|
|
6
6
|
"sass": "dpr/all.scss",
|
|
7
7
|
"engines": {
|
package/package.zip
CHANGED
|
Binary file
|