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.

35 lines (31 loc) 1.39 kB
'use strict'; var UserReports = require('../../../../../types/UserReports.js'); var Report = require('../../../../../components/_reports/Report.js'); var localsHelper = require('../../../../../utils/localsHelper.js'); var utils = require('../../utils.js'); const renderReport = async ({ req, res, services }) => { const { token, dprUser, definitionsPath } = localsHelper.default.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, UserReports.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: UserReports.ReportType.REPORT, reportId, id, reportName, description, name, }; await utils.updateLastViewedSync(req, res, services, stateData, dprUser.id, fields); } return reportConfig; }; exports.renderReport = renderReport; //# sourceMappingURL=utils.js.map