@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
60 lines (57 loc) • 2.53 kB
JavaScript
import localsHelper from '../../../../utils/localsHelper.js';
import { buildMyReportListRow } from '../../../../components/my-reports/my-reports-list-item/utils.js';
import { ListType } from '../../../../components/my-reports/types.js';
import { createReportPollingHandler } from '../../../../controllers/reportPolling/createReportPollingHandler.js';
import { initRequested } from '../../../../components/my-reports/utils.js';
import { captureDprError } from '../../../../utils/captureError.js';
import { removeMyReport, getAllMyReports } from '../utils.js';
class RequestedReportsController {
services;
GET;
constructor(services) {
this.services = services;
/**
* Gets an individual My Reports row and renders it as a string
*/
this.GET = createReportPollingHandler(this.services, (updated, resolution, req, res) => {
const viewModel = buildMyReportListRow(updated, resolution.newStatus, req, res, ListType.REQUESTED);
return {
template: 'dpr/components/my-reports/my-reports-list-item/row.njk',
data: { item: viewModel },
};
});
}
/**
* Remove requested report action
*
* @param {*} req
* @param {*} res
* @return {*}
*/
POST = async (req, res) => {
const { dprUser } = localsHelper.getValues(res);
const { executionId } = req.params;
// Remove the report
await removeMyReport('requestedReports', { executionId }, this.services, dprUser.id);
// Update the locals
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 initRequested(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 { RequestedReportsController, RequestedReportsController as default };
//# sourceMappingURL=controller.js.map