diff --git a/packages/api/src/routers/export_router.ts b/packages/api/src/routers/export_router.ts index fd7052ece..bd95cf304 100644 --- a/packages/api/src/routers/export_router.ts +++ b/packages/api/src/routers/export_router.ts @@ -3,8 +3,9 @@ import express, { Router } from 'express' import { TaskState } from '../generated/graphql' import { jobStateToTaskState } from '../queue-processor' import { - countExportsWithin24Hours, + countExportsWithin6Hours, countExportsWithinMinute, + findExports, saveExport, } from '../services/export' import { getClaimsByToken, getTokenByRequest } from '../utils/auth' @@ -42,9 +43,9 @@ export function exportRouter() { }) } - const exportsWithin24Hours = await countExportsWithin24Hours(userId) + const exportsWithin24Hours = await countExportsWithin6Hours(userId) if (exportsWithin24Hours >= 3) { - logger.error('User has reached the limit of exports within 24 hours', { + logger.error('User has reached the limit of exports within 6 hours', { userId, exportsWithin24Hours, }) @@ -97,5 +98,37 @@ export function exportRouter() { } }) + // eslint-disable-next-line @typescript-eslint/no-misused-promises + router.get('/list', cors(corsConfig), async (req, res) => { + const token = getTokenByRequest(req) + // get claims from token + const claims = await getClaimsByToken(token) + if (!claims) { + logger.error('Token not found') + return res.status(401).send({ + error: 'UNAUTHORIZED', + }) + } + + // get user by uid from claims + const userId = claims.uid + + try { + const exports = await findExports(userId) + + res.send({ + exports, + }) + } catch (error) { + logger.error('Error fetching exports', { + userId, + error, + }) + return res.status(500).send({ + error: 'INTERNAL_ERROR', + }) + } + }) + return router } diff --git a/packages/web/lib/networking/useCreateExport.tsx b/packages/web/lib/networking/useCreateExport.tsx index de2f5bd9b..6ed510090 100644 --- a/packages/web/lib/networking/useCreateExport.tsx +++ b/packages/web/lib/networking/useCreateExport.tsx @@ -5,6 +5,8 @@ import { TaskState } from './mutations/exportToIntegrationMutation' type Export = { id: string state: TaskState + totalItems?: number + processedItems?: number createdAt: string signedUrl: string } diff --git a/packages/web/pages/settings/account.tsx b/packages/web/pages/settings/account.tsx index 1271dd335..cb25fcc9f 100644 --- a/packages/web/pages/settings/account.tsx +++ b/packages/web/pages/settings/account.tsx @@ -535,13 +535,31 @@ const ExportSection = (): JSX.Element => { return ( {timeAgo(item.createdAt)} - {item.state} + {item.state} + {item.totalItems && ( + + + + {`${item.processedItems ?? 0} of ${ + item.totalItems + } items.`} + + + )} {item.signedUrl && (