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.

57 lines (54 loc) 2.31 kB
import localsHelper from '../../../../../utils/localsHelper.js'; import { LoadType } from '../../../../../types/UserReports.js'; import logger from '../../../../../utils/logger.js'; import { getActiveJourneyValue } from '../../../../../utils/sessionHelper.js'; class RequestDownloadController { layoutPath; services; constructor(layoutPath, services) { this.layoutPath = layoutPath; this.services = services; } GET = async (req, res, next) => { const { token, csrfToken, definitionsPath, dprUser } = localsHelper.getValues(res); const { reportId, variantId, tableId } = req.params; const loadType = tableId ? LoadType.ASYNC : LoadType.SYNC; const currentReportUrl = getActiveJourneyValue(req, { id: variantId, reportId, tableId }, 'currentReportUrl'); // Get the validation errors const validationErrors = res.locals['validationErrors'] || []; const variantData = await this.services.reportingService.getDefinition(token, reportId, variantId, definitionsPath); try { res.render(`dpr/routes/journeys/download-report/request-download/form/view`, { title: 'Download request form', user: { id: dprUser.id, activeCaseLoadId: dprUser.activeCaseLoadId, staffId: dprUser.staffId, }, report: { reportId, reportName: variantData.name, variantId, variantName: variantData.variant.name, loadType, time: new Date().toDateString(), reportUrl: currentReportUrl, }, validationErrors, csrfToken, layoutPath: this.layoutPath, }); } catch (error) { next(error); } }; POST = async (req, res, _next) => { const { body, baseUrl } = req; logger.info('Download Feedback Submission:', `${JSON.stringify(body)}`); const redirect = `${baseUrl}/submitted`; res.redirect(redirect); }; } export { RequestDownloadController, RequestDownloadController as default }; //# sourceMappingURL=controller.js.map