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.

44 lines (41 loc) 2.01 kB
import localsHelper from '../../../../utils/localsHelper.js'; import { initViewed } from '../../../../components/my-reports/utils.js'; import { captureDprError } from '../../../../utils/captureError.js'; import { removeMyReport, getAllMyReports } from '../utils.js'; class RecentlyViewedReportsController { services; constructor(services) { this.services = services; } POST = async (req, res) => { const { dprUser } = localsHelper.getValues(res); const { id, reportId, tableId, executionId } = req.params; // Remove the report from recenly viewed list await removeMyReport('recentlyViewedReports', { reportId, id, tableId }, this.services, dprUser.id); // And clean up the request data, if there is any if (executionId) { await removeMyReport('requestedReports', { executionId }, this.services, dprUser.id); } // Update the locals res.locals['recentlyViewedReports'] = await getAllMyReports('recentlyViewedReports', this.services, dprUser.id); res.locals['requestedReports'] = await getAllMyReports('requestedReports', this.services, dprUser.id); try { // get the data for the requested list const maxRows = req.body?.maxRows !== undefined ? Number(req.body.maxRows) : undefined; const viewModel = await initViewed(req, res, { ...(maxRows && { maxRows }), }); return res.render('dpr/components/my-reports/my-reports-list/view.njk', { viewModel }, (err, html) => { if (err) return res.sendStatus(500); return res.type('text/html').send(html); }); } catch (error) { captureDprError(error, 'Failed to refresh list after removal'); return res.sendStatus(500); } }; } export { RecentlyViewedReportsController, RecentlyViewedReportsController as default }; //# sourceMappingURL=controller.js.map