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.44 kB
'use strict'; var UserReports = require('../../../../../types/UserReports.js'); var localsHelper = require('../../../../../utils/localsHelper.js'); var utils = require('../../utils.js'); var Dashboard = require('../../../../../components/_dashboards/Dashboard.js'); const renderDashboard = 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.dashboardService.getDefinition(token, reportId, id, definitionsPath)); // Create the report config const dashboardConfig = await new Dashboard(services, res, req, definition, UserReports.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: UserReports.ReportType.REPORT, reportId, id, reportName, description, name, }; await utils.updateLastViewedSync(req, res, services, stateData, dprUser.id, fields); } return dashboardConfig; }; exports.renderDashboard = renderDashboard; //# sourceMappingURL=utils.js.map