@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
49 lines (44 loc) • 2.15 kB
JavaScript
;
Object.defineProperty(exports, '__esModule', { value: true });
var localsHelper = require('../../../../utils/localsHelper.js');
var utils$1 = require('../../../../components/my-reports/utils.js');
var captureError = require('../../../../utils/captureError.js');
var utils = require('../utils.js');
class RecentlyViewedReportsController {
services;
constructor(services) {
this.services = services;
}
POST = async (req, res) => {
const { dprUser } = localsHelper.default.getValues(res);
const { id, reportId, tableId, executionId } = req.params;
// Remove the report from recenly viewed list
await utils.removeMyReport('recentlyViewedReports', { reportId, id, tableId }, this.services, dprUser.id);
// And clean up the request data, if there is any
if (executionId) {
await utils.removeMyReport('requestedReports', { executionId }, this.services, dprUser.id);
}
// Update the locals
res.locals['recentlyViewedReports'] = await utils.getAllMyReports('recentlyViewedReports', this.services, dprUser.id);
res.locals['requestedReports'] = await utils.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 utils$1.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) {
captureError.captureDprError(error, 'Failed to refresh list after removal');
return res.sendStatus(500);
}
};
}
exports.RecentlyViewedReportsController = RecentlyViewedReportsController;
exports.default = RecentlyViewedReportsController;
//# sourceMappingURL=controller.js.map