'use strict';

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

const renderReport = async ({ req, res, services }) => {
    const { token, dprUser, definitionsPath } = localsHelper.default.getValues(res);
    const { id, reportId } = req.params;
    // Get the definition
    const definition = await services.reportingService.getDefinition(token, reportId, id, definitionsPath);
    // Create the report config
    const reportConfig = await new Report(services, res, req, definition, UserReports.LoadType.SYNC).build();
    // Save the data to redis
    if (reportConfig && Object.keys(reportConfig.renderData).length) {
        const { renderData } = reportConfig;
        const { reportName, description, name, fields } = renderData;
        const stateData = {
            type: UserReports.ReportType.REPORT,
            reportId,
            id,
            reportName,
            description,
            name,
        };
        await utils.updateLastViewedSync(req, services, stateData, dprUser.id, fields);
    }
    return reportConfig;
};

exports.renderReport = renderReport;
//# sourceMappingURL=utils.js.map
