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.

28 lines (25 loc) 1.38 kB
import { LoadType } from '../../../../../types/UserReports.js'; import Report from '../../../../../components/_reports/Report.js'; import localsHelper from '../../../../../utils/localsHelper.js'; import { updateLastViewedAsync } from '../../utils.js'; import { getMyReport } from '../../../my-reports/utils.js'; const renderReport = async ({ req, res, services }) => { const { token, dprUser, definitionsPath } = localsHelper.getValues(res); const { id, tableId, reportId } = req.params; const requestData = await getMyReport({ tableId }, 'requestedReports', services, dprUser.id); // get pre-filter query data required by getDefinition const queryData = requestData?.query?.data; // Get the definition const definition = res.locals['definition'] ?? (await services.reportingService.getDefinition(token, reportId, id, definitionsPath, queryData)); // Create the report config const reportConfig = await new Report(services, res, req, definition, LoadType.ASYNC, requestData).build(); const { renderData } = reportConfig; if (renderData && requestData && Object.keys(requestData).length) { // Save the data to redis await updateLastViewedAsync(req, res, services, requestData, dprUser.id, renderData.fields || []); } return reportConfig; }; export { renderReport }; //# sourceMappingURL=utils.js.map