'use strict';

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

var ErrorHandler = require('../../../../../utils/ErrorHandler/ErrorHandler.js');
var localsHelper = require('../../../../../utils/localsHelper.js');
var utils = require('./utils.js');
var utils$1 = require('../../utils.js');

class ViewAsyncDashboardController {
    layoutPath;
    services;
    constructor(layoutPath, services) {
        this.layoutPath = layoutPath;
        this.services = services;
    }
    GET = async (req, res, next) => {
        const { type, tableId } = req.params;
        try {
            const params = { req, res, services: this.services, next };
            const renderData = await utils.default.renderAsyncDashboard(params);
            res.render(`dpr/routes/journeys/view-report/dashboard`, {
                layoutPath: this.layoutPath,
                ...renderData,
            });
        }
        catch (error) {
            const dprError = new ErrorHandler.ErrorHandler(error).formatError();
            let refreshLink;
            if (dprError.status === 'EXPIRED') {
                const { dprUser } = localsHelper.default.getValues(res);
                refreshLink = await this.services.recentlyViewedService.asyncSetToExpiredByTableId(tableId, dprUser.id);
            }
            req.body ??= {};
            req.body.title = `Failed to retrieve ${type}`;
            req.body.error = dprError;
            if (refreshLink) {
                req.body.refreshLink = refreshLink;
            }
            next(error);
        }
    };
    applyFilters = async (req, res, _next) => {
        await utils$1.default.applyDashboardInteractiveQuery(req, res, this.services, 'filters');
    };
}

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