import localsHelper from '../utils/localsHelper.js';
import { getDefinitionByType } from '../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.getValues(res);
            const { reportId, id, type: reportType } = req.params;
            const { definition } = await getDefinitionByType(reportType, services, token, reportId, id, definitionsPath);
            res.locals.definition = definition;
            next();
        }
        catch (err) {
            next(err);
        }
    };
};

export { loadReportDefinition };
//# sourceMappingURL=loadReportDefinition.js.map
