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.35 kB
import { LoadType, ReportType } from '../../../../../types/UserReports.js'; import Report from '../../../../../components/_reports/Report.js'; import localsHelper from '../../../../../utils/localsHelper.js'; import { updateLastViewedSync } from '../../utils.js'; const renderReport = 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.reportingService.getDefinition(token, reportId, id, definitionsPath)); // Create the report config const reportConfig = await new Report(services, res, req, definition, LoadType.SYNC).build(); // Save the data to redis if (reportConfig && reportConfig.renderData && Object.keys(reportConfig.renderData).length) { const { renderData } = reportConfig; const { reportName, description, name, fields } = renderData; const stateData = { type: ReportType.REPORT, reportId, id, reportName, description, name, }; await updateLastViewedSync(req, res, services, stateData, dprUser.id, fields); } return reportConfig; }; export { renderReport }; //# sourceMappingURL=utils.js.map