import { getCurrentVariantDefinition } from './definitionUtils.js';

/**
 * Get all Requested and Viewed reports
 *
 * @param {Response} res
 * @param {Services} services
 * @param {string} dprUserId
 * @return {*}
 */
const getAllMyReports = async (res, services, dprUserId) => {
    const { definitions, definitionsPath } = res.locals;
    // 1. Get the recently viewed reports
    let recentlyViewedReports = await services.recentlyViewedService.getAllReports(dprUserId);
    recentlyViewedReports = !definitionsPath
        ? recentlyViewedReports
        : recentlyViewedReports.filter((report) => {
            return getCurrentVariantDefinition(definitions, report.reportId, report.id);
        });
    // 2. Clean and get requested reports
    await services.requestedReportService.cleanList(dprUserId, recentlyViewedReports);
    let requestedReports = await services.requestedReportService.getAllReports(dprUserId);
    requestedReports = !definitionsPath
        ? requestedReports
        : requestedReports.filter((report) => {
            return getCurrentVariantDefinition(definitions, report.reportId, report.id);
        });
    return {
        requestedReports,
        recentlyViewedReports,
    };
};
/**
 * Get all the bookmarks
 *
 * @param {Response} res
 * @param {Services} services
 * @param {string} dprUserId
 * @return {*}
 */
const getAllMyBookmarks = async (res, services, dprUserId) => {
    const { definitions, definitionsPath } = res.locals;
    let bookmarks = await services.bookmarkService.getAllBookmarks(dprUserId);
    bookmarks = !definitionsPath
        ? bookmarks
        : bookmarks.filter((bookmark) => {
            return getCurrentVariantDefinition(definitions, bookmark.reportId, bookmark.id);
        });
    return bookmarks;
};

export { getAllMyBookmarks, getAllMyReports };
//# sourceMappingURL=reportStoreHelper.js.map
