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.

33 lines (30 loc) 1.39 kB
import { LoadType, ReportType } from '../../../../../types/UserReports.js'; import localsHelper from '../../../../../utils/localsHelper.js'; import { updateLastViewedSync } from '../../utils.js'; import Dashboard from '../../../../../components/_dashboards/Dashboard.js'; const renderDashboard = async ({ req, res, services }) => { const { token, dprUser, definitionsPath } = localsHelper.getValues(res); const { id, reportId } = req.params; // Get the definition const definition = res.locals['definition'] ?? (await services.dashboardService.getDefinition(token, reportId, id, definitionsPath)); // Create the report config const dashboardConfig = await new Dashboard(services, res, req, definition, LoadType.SYNC).build(); // Save the data to redis if (dashboardConfig && dashboardConfig.dashboardData && Object.keys(dashboardConfig.dashboardData).length) { const { dashboardData } = dashboardConfig; const { reportName, description, name, fields } = dashboardData; const stateData = { type: ReportType.REPORT, reportId, id, reportName, description, name, }; await updateLastViewedSync(req, res, services, stateData, dprUser.id, fields); } return dashboardConfig; }; export { renderDashboard }; //# sourceMappingURL=utils.js.map