'use strict';

Object.defineProperty(exports, '__esModule', { value: true });

var node = require('@sentry/node');
var utils = require('./utils.js');
var utils$1 = require('../../../../components/user-reports/requested/utils.js');
var ErrorHandler = require('../../../../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 utils.default.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.ErrorHandler(error).formatError();
            next(error);
        }
    };
    // Poll request status
    POST = async (req, res, _next) => {
        try {
            const response = await utils$1.default.getRequestStatus({ req, res, services: this.services });
            res.send({ status: response.status });
        }
        catch (error) {
            node.captureException(error);
            res.send({ status: 'FAILED' });
        }
    };
}

exports.RequestStatusController = RequestStatusController;
exports.default = RequestStatusController;
//# sourceMappingURL=controller.js.map
