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.

65 lines (60 loc) 2.4 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var localsHelper = require('../../../../../utils/localsHelper.js'); var UserReports = require('../../../../../types/UserReports.js'); class LoadReportController { layoutPath; services; constructor(layoutPath, services) { this.layoutPath = layoutPath; this.services = services; } GET = async (req, res, next) => { try { const { token, definitionsPath } = localsHelper.default.getValues(res); const { reportId, id, type } = req.params; const definitionSummary = res.locals['reportDefinitionSummary'] ?? (await this.services.reportingService.getDefinitionSummary(token, reportId, definitionsPath)); let definition; let classification; let description; let name; if (type === UserReports.ReportType.REPORT) { definition = res.locals['definition'] ?? (await this.services.reportingService.getDefinition(token, reportId, id, definitionsPath)); const { variant } = definition; classification = variant.classification; description = variant.description; name = variant.name; } else { definition = res.locals['definition'] ?? (await this.services.dashboardService.getDefinition(token, reportId, id, definitionsPath)); description = definition.description; name = definition.name; } const { name: reportName, description: reportDescription } = definitionSummary; const renderData = { reportId, id, type, reportName, name, classification, description: description || reportDescription, }; res.render(`dpr/routes/journeys/view-report/sync/load-report/view`, { renderData, layoutPath: this.layoutPath, }); } catch (error) { next(error); } }; } exports.LoadReportController = LoadReportController; exports.default = LoadReportController; //# sourceMappingURL=controller.js.map