UNPKG

@ministryofjustice/hmpps-digital-prison-reporting-frontend

Version:

The Digital Prison Reporting Frontend contains templates and code to help display data effectively in UI applications.

95 lines (92 loc) 3.65 kB
import { getCurrentVariantDefinition } from './definitionUtils.js'; import { getAllMyReports as getAllMyReports$1 } from '../routes/journeys/my-reports/utils.js'; /** * Get all Requested and Viewed reports * * @param {Response} res * @param {Services} services * @param {string} dprUserId * @return {*} */ const getAllMyReports = async (res, services, dprUserId) => { const recentlyViewedReports = await getRecentlyViewedReports(res, services, dprUserId); const requestedReports = await getRequestedReports(res, services, dprUserId); const subscriptions = await getSubscriptions(res, services, dprUserId); return { requestedReports, recentlyViewedReports, subscriptions, }; }; const getRecentlyViewedReports = async (res, services, dprUserId) => { const { definitions, definitionsPath } = res.locals; // 1. Get the recently viewed reports let recentlyViewedReports = await getAllMyReports$1('recentlyViewedReports', services, 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); return recentlyViewedReports; }; const getRequestedReports = async (res, services, dprUserId) => { const { definitions, definitionsPath } = res.locals; let requestedReports = await getAllMyReports$1('requestedReports', services, dprUserId); requestedReports = !definitionsPath ? requestedReports : requestedReports.filter((report) => { return getCurrentVariantDefinition(definitions, report.reportId, report.id); }); return requestedReports; }; const getSubscriptions = async (res, services, dprUserId) => { const { definitions, definitionsPath, token, dprUser } = res.locals; let subscriptions = await getAllMyReports$1('subscriptions', services, dprUserId); if (subscriptions.length) { subscriptions = !definitionsPath ? subscriptions : subscriptions.filter((report) => { return getCurrentVariantDefinition(definitions, report.reportId, report.id); }); const timestampData = await services.subscriptionService.getSubscriptions(token); subscriptions = await services.subscriptionStoreService.updateTimestamps(timestampData, dprUser.id); } return subscriptions; }; /** * 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; }; /** * Gets the report title data from report state * - old versions of the schema store use variantName * * @param {StoredReportData} data * @return {*} */ const getReportTitleData = (data) => { const productName = data.reportName ?? 'unknown-product'; const reportName = data.name ?? data.variantName ?? 'unknown-report'; return { productName, reportName, }; }; export { getAllMyBookmarks, getAllMyReports, getReportTitleData }; //# sourceMappingURL=reportStoreHelper.js.map