'use strict';

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

var localsHelper = require('../utils/localsHelper.js');
var UserReports = require('../types/UserReports.js');

const reportAuthoriser = (services, layoutPath) => {
    return async (req, res, next) => {
        const { token } = localsHelper.default.getValues(res);
        const { reportId, id, variantId, type } = req.params;
        const dataProductDefinitionsPath = req.query['dataProductDefinitionsPath'];
        const definitionSummary = await services.reportingService.getDefinitionSummary(token, reportId, dataProductDefinitionsPath);
        const service = type === UserReports.ReportType.REPORT ? services.reportingService : services.dashboardService;
        res.locals['definition'] = await service.getDefinition(token, reportId, (variantId || id), dataProductDefinitionsPath);
        if (definitionSummary?.authorised !== undefined && !definitionSummary.authorised) {
            res.render(`dpr/routes/journeys/view-report/unauthorised`, {
                layoutPath,
                ...req.body,
            });
        }
        else {
            next();
        }
    };
};

exports.default = reportAuthoriser;
exports.reportAuthoriser = reportAuthoriser;
//# sourceMappingURL=reportAuthoriser.js.map
