@ministryofjustice/hmpps-digital-prison-reporting-frontend 3.8.0 → 3.8.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.
@@ -4,6 +4,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  /* eslint-disable no-underscore-dangle */
7
+ const parseurl_1 = __importDefault(require("parseurl"));
7
8
  const utils_1 = __importDefault(require("../data-table/utils"));
8
9
  const utils_2 = __importDefault(require("../async-columns/utils"));
9
10
  const utils_3 = __importDefault(require("../pagination/utils"));
@@ -29,7 +30,7 @@ const initDataSources = ({ req, res, next, asyncReportsStore, dataSources }) =>
29
30
  }
30
31
  };
31
32
  exports.default = {
32
- renderReport: async ({ req, res, next, url, asyncReportsStore, dataSources }) => {
33
+ renderReport: async ({ req, res, next, asyncReportsStore, dataSources }) => {
33
34
  const { columns: reqColumns } = req.query;
34
35
  const dataPromises = initDataSources({ req, res, next, dataSources, asyncReportsStore });
35
36
  let renderData = {};
@@ -43,6 +44,7 @@ exports.default = {
43
44
  const fieldDefinition = definition.variant.specification.fields;
44
45
  const { classification } = definition.variant;
45
46
  const columns = utils_2.default.getColumns(fieldDefinition, reqColumns);
47
+ const url = (0, parseurl_1.default)(req);
46
48
  const pagination = utils_3.default.getPaginationData(url, count);
47
49
  const actions = utils_4.default.initReportActions(definition.variant, reportStateData);
48
50
  const rows = utils_1.default.mapData(reportData, fieldDefinition, columns.value);
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
+ import parseUrl from 'parseurl'
2
3
  import DataTableUtils from '../data-table/utils'
3
4
  import ColumnUtils from '../async-columns/utils'
4
5
  import PaginationUtils from '../pagination/utils'
@@ -31,7 +32,7 @@ const initDataSources = ({ req, res, next, asyncReportsStore, dataSources }: Asy
31
32
  }
32
33
 
33
34
  export default {
34
- renderReport: async ({ req, res, next, url, asyncReportsStore, dataSources }: AsyncReportUtilsParams) => {
35
+ renderReport: async ({ req, res, next, asyncReportsStore, dataSources }: AsyncReportUtilsParams) => {
35
36
  const { columns: reqColumns } = req.query
36
37
  const dataPromises = initDataSources({ req, res, next, dataSources, asyncReportsStore })
37
38
 
@@ -47,6 +48,7 @@ export default {
47
48
  const { classification } = definition.variant
48
49
 
49
50
  const columns = ColumnUtils.getColumns(fieldDefinition, <string[]>reqColumns)
51
+ const url = parseUrl(req)
50
52
  const pagination = PaginationUtils.getPaginationData(url, count)
51
53
  const actions = ReportActionsUtils.initReportActions(definition.variant, reportStateData)
52
54
  const rows = DataTableUtils.mapData(reportData, fieldDefinition, columns.value)
@@ -1,4 +1,5 @@
1
- import { Page, UrlData } from './types'
1
+ import { Url } from 'url'
2
+ import { Page } from './types'
2
3
 
3
4
  const SELECTED_PAGE_PARAM = 'selectedPage'
4
5
  const PAGE_SIZE_PARAM = 'pageSize'
@@ -121,7 +122,7 @@ const setPageSizes = (totalRows: number) => {
121
122
  * @return {*}
122
123
  */
123
124
  export default {
124
- getPaginationData: (url: UrlData, totalRows: number) => {
125
+ getPaginationData: (url: Url, totalRows: number) => {
125
126
  const { pathname, search } = url
126
127
  const { pages, pagesLength } = createPages(pathname, search, totalRows)
127
128
  return {
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ const utils_1 = __importDefault(require("../components/async-filters/utils"));
7
+ const utils_2 = __importDefault(require("../components/async-report-list/utils"));
8
+ const utils_3 = __importDefault(require("../components/async-polling/utils"));
9
+ function routes({ router, asyncReportsStore, dataSources, }) {
10
+ // 1 - get filters for the report + make request
11
+ router.get('/async-reports/:reportId/:variantId/request', async (req, res, next) => {
12
+ res.render('async-request.njk', {
13
+ title: 'Request Report',
14
+ postEndpoint: '/requestReport/',
15
+ ...(await utils_1.default.renderFilters({ req, res, dataSources, next })),
16
+ });
17
+ });
18
+ // 2 - handle the post request to request the report data
19
+ router.post('/requestReport/', async (req, res, next) => {
20
+ const redirectToPollingPage = await utils_1.default.requestReport({
21
+ req,
22
+ res,
23
+ dataSources,
24
+ asyncReportsStore,
25
+ next,
26
+ });
27
+ if (redirectToPollingPage) {
28
+ res.redirect(redirectToPollingPage);
29
+ }
30
+ res.end();
31
+ });
32
+ // 3 - polling the status of the request
33
+ router.get('/async-reports/:reportId/:variantId/request/:executionId', async (req, res, next) => {
34
+ res.render('async-polling.njk', {
35
+ title: 'Report Requested',
36
+ ...(await utils_3.default.renderPolling({ req, res, dataSources, asyncReportsStore, next })),
37
+ });
38
+ });
39
+ // 3 - load the report data
40
+ router.get('/async-reports/:reportId/:reportVariantId/request/:tableId/report', async (req, res, next) => {
41
+ res.render('async-report.njk', {
42
+ ...(await utils_2.default.renderReport({
43
+ req,
44
+ res,
45
+ dataSources,
46
+ asyncReportsStore,
47
+ next,
48
+ })),
49
+ });
50
+ });
51
+ }
52
+ exports.default = routes;
@@ -1,13 +1,22 @@
1
1
  /* eslint-disable no-underscore-dangle */
2
- // eslint-disable-next-line import/no-extraneous-dependencies
3
- const bodyParser = require('body-parser')
4
- const AsyncFiltersUtils = require('../../components/async-filters/utils').default
5
- const AsyncReportListUtils = require('../../components/async-report-list/utils').default
6
- const AsyncPollingUtils = require('../../components/async-polling/utils').default
2
+ import type { Router } from 'express'
3
+ import AsyncFiltersUtils from '../components/async-filters/utils'
4
+ import AsyncReportListUtils from '../components/async-report-list/utils'
5
+ import AsyncPollingUtils from '../components/async-polling/utils'
6
+ import ReportingClient from '../data/reportingClient'
7
+ import AsyncReportStoreService from '../services/requestedReportsService'
7
8
 
8
- const addAsyncReportingRoutes = ({ app, asyncReportsStore, dataSources }) => {
9
+ export default function routes({
10
+ router,
11
+ asyncReportsStore,
12
+ dataSources,
13
+ }: {
14
+ router: Router
15
+ asyncReportsStore: AsyncReportStoreService
16
+ dataSources: ReportingClient
17
+ }) {
9
18
  // 1 - get filters for the report + make request
10
- app.get('/async-reports/:reportId/:variantId/request', async (req, res, next) => {
19
+ router.get('/async-reports/:reportId/:variantId/request', async (req, res, next) => {
11
20
  res.render('async-request.njk', {
12
21
  title: 'Request Report',
13
22
  postEndpoint: '/requestReport/',
@@ -16,8 +25,7 @@ const addAsyncReportingRoutes = ({ app, asyncReportsStore, dataSources }) => {
16
25
  })
17
26
 
18
27
  // 2 - handle the post request to request the report data
19
- app.use(bodyParser.json())
20
- app.post('/requestReport/', async (req, res, next) => {
28
+ router.post('/requestReport/', async (req, res, next) => {
21
29
  const redirectToPollingPage = await AsyncFiltersUtils.requestReport({
22
30
  req,
23
31
  res,
@@ -25,12 +33,14 @@ const addAsyncReportingRoutes = ({ app, asyncReportsStore, dataSources }) => {
25
33
  asyncReportsStore,
26
34
  next,
27
35
  })
28
- res.redirect(redirectToPollingPage)
36
+ if (redirectToPollingPage) {
37
+ res.redirect(redirectToPollingPage)
38
+ }
29
39
  res.end()
30
40
  })
31
41
 
32
42
  // 3 - polling the status of the request
33
- app.get('/async-reports/:reportId/:variantId/request/:executionId', async (req, res, next) => {
43
+ router.get('/async-reports/:reportId/:variantId/request/:executionId', async (req, res, next) => {
34
44
  res.render('async-polling.njk', {
35
45
  title: 'Report Requested',
36
46
  ...(await AsyncPollingUtils.renderPolling({ req, res, dataSources, asyncReportsStore, next })),
@@ -38,18 +48,15 @@ const addAsyncReportingRoutes = ({ app, asyncReportsStore, dataSources }) => {
38
48
  })
39
49
 
40
50
  // 3 - load the report data
41
- app.get('/async-reports/:reportId/:reportVariantId/request/:tableId/report', async (req, res, next) => {
51
+ router.get('/async-reports/:reportId/:reportVariantId/request/:tableId/report', async (req, res, next) => {
42
52
  res.render('async-report.njk', {
43
53
  ...(await AsyncReportListUtils.renderReport({
44
54
  req,
45
55
  res,
46
56
  dataSources,
47
57
  asyncReportsStore,
48
- url: req._parsedUrl,
49
58
  next,
50
59
  })),
51
60
  })
52
61
  })
53
62
  }
54
-
55
- module.exports = addAsyncReportingRoutes
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class ReportingService {
4
+ constructor(reportingClient) {
5
+ this.reportingClient = reportingClient;
6
+ }
7
+ async getCount(resourceName, token, listRequest) {
8
+ return this.reportingClient.getCount(resourceName, token, listRequest);
9
+ }
10
+ async getList(resourceName, token, listRequest) {
11
+ return this.reportingClient.getList(resourceName, token, listRequest);
12
+ }
13
+ async getDefinitions(token, dataProductDefinitionsPath) {
14
+ return this.reportingClient.getDefinitions(token, dataProductDefinitionsPath);
15
+ }
16
+ async requestAsyncReport(token, reportId, variantId, query) {
17
+ return this.reportingClient.requestAsyncReport(token, reportId, variantId, query);
18
+ }
19
+ async getAsyncReport(token, reportId, variantId, tableId, query) {
20
+ return this.reportingClient.getAsyncReport(token, reportId, variantId, tableId, query);
21
+ }
22
+ async getAsyncReportStatus(token, reportId, variantId, executionId) {
23
+ return this.reportingClient.getAsyncReportStatus(token, reportId, variantId, executionId);
24
+ }
25
+ async getAsyncCount(token, tableId) {
26
+ return this.reportingClient.getAsyncCount(token, tableId);
27
+ }
28
+ }
29
+ exports.default = ReportingService;
@@ -0,0 +1,55 @@
1
+ import { components } from '../types/api'
2
+ import type ReportingClient from '../data/reportingClient'
3
+ import ReportQuery from '../types/ReportQuery'
4
+ import Dict = NodeJS.Dict
5
+
6
+ export default class ReportingService {
7
+ constructor(private readonly reportingClient: ReportingClient) {}
8
+
9
+ async getCount(resourceName: string, token: string, listRequest: ReportQuery): Promise<number> {
10
+ return this.reportingClient.getCount(resourceName, token, listRequest)
11
+ }
12
+
13
+ async getList(resourceName: string, token: string, listRequest: ReportQuery): Promise<Array<NodeJS.Dict<string>>> {
14
+ return this.reportingClient.getList(resourceName, token, listRequest)
15
+ }
16
+
17
+ async getDefinitions(
18
+ token: string,
19
+ dataProductDefinitionsPath?: string,
20
+ ): Promise<Array<components['schemas']['ReportDefinitionSummary']>> {
21
+ return this.reportingClient.getDefinitions(token, dataProductDefinitionsPath)
22
+ }
23
+
24
+ async requestAsyncReport(
25
+ token: string,
26
+ reportId: string,
27
+ variantId: string,
28
+ query: Record<string, string | boolean | number>,
29
+ ): Promise<Dict<string>> {
30
+ return this.reportingClient.requestAsyncReport(token, reportId, variantId, query)
31
+ }
32
+
33
+ async getAsyncReport(
34
+ token: string,
35
+ reportId: string,
36
+ variantId: string,
37
+ tableId: string,
38
+ query: Dict<string | number>,
39
+ ): Promise<Array<Dict<string>>> {
40
+ return this.reportingClient.getAsyncReport(token, reportId, variantId, tableId, query)
41
+ }
42
+
43
+ async getAsyncReportStatus(
44
+ token: string,
45
+ reportId: string,
46
+ variantId: string,
47
+ executionId: string,
48
+ ): Promise<Dict<string>> {
49
+ return this.reportingClient.getAsyncReportStatus(token, reportId, variantId, executionId)
50
+ }
51
+
52
+ async getAsyncCount(token: string, tableId: string): Promise<number> {
53
+ return this.reportingClient.getAsyncCount(token, tableId)
54
+ }
55
+ }
@@ -1,13 +1,11 @@
1
1
  import { Response, Request, NextFunction } from 'express'
2
2
  import AsyncReportStoreService from '../services/requestedReportsService'
3
- import ReportingClient from '../data/reportingClient'
4
- import { UrlData } from '../components/pagination/types'
3
+ import ReportingService from '../services/reportingService'
5
4
 
6
5
  export interface AsyncReportUtilsParams {
7
6
  req?: Request
8
7
  res: Response
9
8
  next?: NextFunction
10
- dataSources?: ReportingClient
9
+ dataSources?: ReportingService
11
10
  asyncReportsStore?: AsyncReportStoreService
12
- url?: UrlData
13
11
  }
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.8.0",
4
+ "version": "3.8.2",
5
5
  "main": "dpr/assets/js/all.mjs",
6
6
  "sass": "dpr/all.scss",
7
7
  "engines": {
package/package.zip CHANGED
Binary file