@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
32 lines (24 loc) • 1.01 kB
text/typescript
import { RequestHandler } from 'express'
import LocalsHelper from '../../../utils/localsHelper'
import DownloadUtils from './utils'
import { Services } from '../../../types/Services'
export default class DownloadReportController {
layoutPath: string
services: Services
constructor(layoutPath: string, services: Services) {
this.layoutPath = layoutPath
this.services = services
}
POST: RequestHandler = async (req, res, next) => {
const { userId } = LocalsHelper.getValues(res)
const { reportId, id, loadType, currentUrl, currentQueryParams } = req.body
let redirect = `${currentUrl}/download-disabled`
redirect = currentQueryParams ? `${redirect}${currentQueryParams}` : redirect
const canDownload = await this.services.downloadPermissionService.downloadEnabled(userId, reportId, id)
if (canDownload) {
await DownloadUtils.downloadReport({ req, res, services: this.services, redirect, loadType })
} else {
res.redirect(redirect)
}
}
}