'use strict';

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

/**
 * Middleware to load the report definition
 * and store it in locals
 *
 * @param {Services} services
 * @return {*}  {RequestHandler}
 */
const loadReportDefinition = (services) => {
    return async (req, res, next) => {
        try {
            const { token, definitionsPath } = localsHelper.default.getValues(res);
            const { reportId, id, type: reportType } = req.params;
            const { definition } = await definitionUtils.getDefinitionByType(reportType, services, token, reportId, id, definitionsPath);
            res.locals.definition = definition;
            next();
        }
        catch (err) {
            next(err);
        }
    };
};

exports.loadReportDefinition = loadReportDefinition;
//# sourceMappingURL=loadReportDefinition.js.map
