@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
60 lines (57 loc) • 2.27 kB
JavaScript
import localsHelper from '../../../../../utils/localsHelper.js';
import { ReportType } from '../../../../../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.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 === 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);
}
};
}
export { LoadReportController, LoadReportController as default };
//# sourceMappingURL=controller.js.map