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.

62 lines (57 loc) 2.47 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var localsHelper = require('../../../../../utils/localsHelper.js'); var UserReports = require('../../../../../types/UserReports.js'); var logger = require('../../../../../utils/logger.js'); var sessionHelper = require('../../../../../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.default.getValues(res); const { reportId, variantId, tableId } = req.params; const loadType = tableId ? UserReports.LoadType.ASYNC : UserReports.LoadType.SYNC; const currentReportUrl = sessionHelper.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.default.info('Download Feedback Submission:', `${JSON.stringify(body)}`); const redirect = `${baseUrl}/submitted`; res.redirect(redirect); }; } exports.RequestDownloadController = RequestDownloadController; exports.default = RequestDownloadController; //# sourceMappingURL=controller.js.map