@ministryofjustice/hmpps-digital-prison-reporting-frontend
Version:
The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.
52 lines (49 loc) • 2.12 kB
JavaScript
import { initPollingView } from './utils.js';
import { ErrorHandler } from '../../../../utils/ErrorHandler/ErrorHandler.js';
import { createReportPollingHandler } from '../../../../controllers/reportPolling/createReportPollingHandler.js';
import { buildCurrentStatusView } from '../../../../components/_async/async-polling/current-status/utils.js';
import { captureDprError } from '../../../../utils/captureError.js';
class RequestStatusController {
layoutPath;
services;
getCurrentStatus;
constructor(layoutPath, services) {
this.layoutPath = layoutPath;
this.services = services;
// Polling current status - render partial
this.getCurrentStatus = createReportPollingHandler(this.services, (updated, resolution, req, res) => {
const viewModel = buildCurrentStatusView(updated, resolution.newStatus, res, req);
return {
template: 'dpr/components/_async/async-polling/current-status/view.njk',
data: { data: viewModel },
};
});
}
// Render status page
GET = async (req, res, next) => {
try {
const pollingRenderData = await initPollingView({
req,
res,
services: this.services,
next,
});
res.render(`dpr/routes/journeys/request-report/status/view`, {
layoutPath: this.layoutPath,
...pollingRenderData,
});
}
catch (error) {
const message = 'Failed to retrieve report status';
const { reportId, executionId, id, type } = req.params;
captureDprError(error, message, { reportId, executionId, id, type });
req.body ??= {};
req.body.title = message;
req.body.errorDescription = 'We were unable to retrieve the report status:';
req.body.error = new ErrorHandler(error).formatError();
next(error);
}
};
}
export { RequestStatusController, RequestStatusController as default };
//# sourceMappingURL=controller.js.map