import { captureException } from '@sentry/node';
import AsyncPollingUtils from './utils.js';
import AsyncRequestListUtils from '../../../../components/user-reports/requested/utils.js';
import { ErrorHandler } from '../../../../utils/ErrorHandler/ErrorHandler.js';

class RequestStatusController {
    layoutPath;
    services;
    constructor(layoutPath, services) {
        this.layoutPath = layoutPath;
        this.services = services;
    }
    // Render status page
    GET = async (req, res, next) => {
        try {
            const pollingRenderData = await AsyncPollingUtils.renderPolling({
                req,
                res,
                services: this.services,
                next,
            });
            res.render(`dpr/routes/journeys/request-report/status/view`, {
                layoutPath: this.layoutPath,
                ...pollingRenderData,
            });
        }
        catch (error) {
            req.body ??= {};
            req.body.title = 'Failed to retrieve report status';
            req.body.errorDescription = 'We were unable to retrieve the report status:';
            req.body.error = new ErrorHandler(error).formatError();
            next(error);
        }
    };
    // Poll request status
    POST = async (req, res, _next) => {
        try {
            const response = await AsyncRequestListUtils.getRequestStatus({ req, res, services: this.services });
            res.send({ status: response.status });
        }
        catch (error) {
            captureException(error);
            res.send({ status: 'FAILED' });
        }
    };
}

export { RequestStatusController, RequestStatusController as default };
//# sourceMappingURL=controller.js.map
