@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
48 lines (41 loc) • 1.35 kB
text/typescript
import { RequestHandler } from 'express'
import { Services } from '../../../../../types/Services'
import LocalsHelper from '../../../../../utils/localsHelper'
import { ReportType } from '../../../../../types/UserReports'
export default class LoadReportController {
layoutPath: string
services: Services
constructor(layoutPath: string, services: Services) {
this.layoutPath = layoutPath
this.services = services
}
GET: RequestHandler = async (req, res, next) => {
try {
const { token } = LocalsHelper.getValues(res)
const { reportId, id } = req.params
const { dataProductDefinitionsPath } = req.query
const definition = await this.services.reportingService.getDefinition(
token,
reportId,
id,
dataProductDefinitionsPath,
)
const { name: reportName, variant, description: reportDescription } = definition
const { classification, description, name } = variant
res.render(`dpr/routes/journeys/view-report/sync/load-report/view`, {
renderData: {
reportId,
id,
type: ReportType.REPORT,
reportName,
name,
classification,
description: description || reportDescription,
},
layoutPath: this.layoutPath,
})
} catch (error) {
next()
}
}
}