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.

41 lines (36 loc) 1.77 kB
'use strict'; Object.defineProperty(exports, '__esModule', { value: true }); var sessionHelper = require('../../../utils/sessionHelper.js'); var localsHelper = require('../../../utils/localsHelper.js'); var utils = require('./utils.js'); class DownloadReportController { layoutPath; services; constructor(layoutPath, services) { this.layoutPath = layoutPath; this.services = services; } POST = async (req, res) => { const { dprUser } = localsHelper.default.getValues(res); const { reportId, id, tableId } = req.params; const sessionKey = tableId ? { reportId, id, tableId } : { reportId, id }; const currentReportSearch = sessionHelper.getActiveJourneyValue(req, sessionKey, 'currentReportSearch'); const currentReportPathname = sessionHelper.getActiveJourneyValue(req, sessionKey, 'currentReportPathname'); // Initialises the redirect back to the report let redirect = currentReportPathname && currentReportPathname.includes('/download-disabled') ? currentReportPathname : `${currentReportPathname}/download-disabled`; redirect = currentReportSearch ? `${redirect}${currentReportSearch}` : redirect; // Check if user has enabled the report for download const canDownloadReport = await this.services.downloadPermissionService.downloadEnabledForReport(dprUser.id, reportId, id); if (canDownloadReport) { await utils.default.downloadReport({ req, res, services: this.services }); } else { res.redirect(redirect); } }; } exports.DownloadReportController = DownloadReportController; exports.default = DownloadReportController; //# sourceMappingURL=controller.js.map