import { LoadType, ReportType } from '../../../../../types/UserReports.js';
import Report from '../../../../../components/_reports/Report.js';
import localsHelper from '../../../../../utils/localsHelper.js';
import { updateLastViewedSync } from '../../utils.js';

const renderReport = async ({ req, res, services }) => {
    const { token, dprUser, definitionsPath } = localsHelper.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, 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: ReportType.REPORT,
            reportId,
            id,
            reportName,
            description,
            name,
        };
        await updateLastViewedSync(req, services, stateData, dprUser.id, fields);
    }
    return reportConfig;
};

export { renderReport };
//# sourceMappingURL=utils.js.map
