UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

60 lines (57 loc) 2.99 kB
import { Router } from 'express'; import { getRouteLocals } from '../../../utils/localsHelper.js'; import { LoadType } from '../../../types/UserReports.js'; import { ViewReportController } from './controller.js'; import routes from './sync/routes.js'; import routes$1 from './async/routes.js'; import { setNestedPath } from '../../../utils/urlHelper.js'; import { storeActiveReportSessionData } from '../../../middleware/setUpActiveReport.js'; import setupCurrentDefinition from '../../../middleware/setupCurrentDefinition.js'; import reportAuthoriser from '../../../middleware/reportAuthoriser.js'; /* eslint-disable no-param-reassign */ function Routes({ layoutPath, services }) { const router = Router({ mergeParams: true }); const controller = new ViewReportController(layoutPath, services); // ------------------- // SYNC // ------------------- router.use(`/sync/:type/:reportId/:id`, setupCurrentDefinition(services), reportAuthoriser(services, layoutPath), storeActiveReportSessionData({ services, loadType: LoadType.SYNC }), routes({ layoutPath, services }), controller.errorHandler); // ------------------- // ASYNC // ------------------- router.use(`/async/:type/:reportId/:id/:tableId`, setupCurrentDefinition(services), reportAuthoriser(services, layoutPath), storeActiveReportSessionData({ services }), routes$1({ layoutPath, services }), controller.errorHandler); return router; } function Redirects() { const router = Router({ mergeParams: true }); // View Report router.get([`/async/:type/:reportId/:id/request/:tableId/:type`], (req, res) => { const { type, reportId, id, tableId } = req.params; const { nestedBaseUrl } = getRouteLocals(res); const path = setNestedPath(`/dpr/view-report/async/${type}/${reportId}/${id}/${tableId}/${type}`, nestedBaseUrl); res.redirect(path); }); // Download router.get(`/async/:type/:reportId/:id/request/:tableId/report/:download`, (req, res) => { const { type, reportId, id, tableId } = req.params; const { nestedBaseUrl } = getRouteLocals(res); const path = setNestedPath(`/dpr/view-report/async/${type}/${reportId}/${id}/${tableId}/${type}`, nestedBaseUrl); res.redirect(path); }); // Expired Status router.post('/async/:type/:reportId/:id/request/:tableId/:type', (req, res) => { const { type, reportId, id, tableId } = req.params; const { nestedBaseUrl } = getRouteLocals(res); const path = setNestedPath(`/dpr/view-report/async/${type}/${reportId}/${id}/${tableId}/${type}`, nestedBaseUrl); res.redirect(308, path); }); return router; } const ViewReportRoutes = ({ services, path, layoutPath, }) => { const router = Router({ mergeParams: true }); router.use(path, Routes({ services, layoutPath })); router.use('/', Redirects()); return router; }; export { Redirects, Routes, ViewReportRoutes }; //# sourceMappingURL=routes.js.map