import { LoadType } from '../../../../../types/UserReports.js';
import Report from '../../../../../components/_reports/Report.js';
import localsHelper from '../../../../../utils/localsHelper.js';
import UserReportsListUtils from '../../../../../components/user-reports/utils.js';

const renderReport = async ({ req, res, services }) => {
    const { token, dprUser, definitionsPath } = localsHelper.getValues(res);
    const { id, tableId, reportId } = req.params;
    const requestData = await services.requestedReportService.getReportByTableId(tableId, dprUser.id);
    // get pre-filter query data required by getDefinition
    const queryData = requestData?.query?.data;
    // Get the definition
    const definition = await services.reportingService.getDefinition(token, reportId, id, definitionsPath, queryData);
    // Create the report config
    const reportConfig = await new Report(services, res, req, definition, LoadType.ASYNC, requestData).build();
    // Save the data to redis
    if (requestData && Object.keys(requestData).length) {
        UserReportsListUtils.updateLastViewed({
            req,
            services,
            reportStateData: requestData,
            userId: dprUser.id,
            filters: reportConfig.renderData.filterData,
        });
    }
    return reportConfig;
};

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