diff --git a/apps/web/src/app/(dashboard)/admin/page.tsx b/apps/web/src/app/(dashboard)/admin/page.tsx index e4a62f725..e72d35dc3 100644 --- a/apps/web/src/app/(dashboard)/admin/page.tsx +++ b/apps/web/src/app/(dashboard)/admin/page.tsx @@ -37,9 +37,9 @@ type TCardData = { | 'NOT_SIGNED' | 'SENT' | 'NOT_SENT'; -}[]; +}; -const CARD_DATA: TCardData = [ +const CARD_DATA: TCardData[] = [ { icon: UserSquare2, title: 'Total recipients in the database', diff --git a/packages/lib/server-only/admin/get-recipients.ts b/packages/lib/server-only/admin/get-recipients.ts index 0be612e55..92c0c3527 100644 --- a/packages/lib/server-only/admin/get-recipients.ts +++ b/packages/lib/server-only/admin/get-recipients.ts @@ -7,14 +7,21 @@ export const getRecipientsStats = async () => { _count: true, }); - return { - TOTAL_RECIPIENTS: results.length, - [ReadStatus.OPENED]: results.filter((r) => r.readStatus === 'OPENED')?.[0]?._count ?? 0, - [ReadStatus.NOT_OPENED]: results.filter((r) => r.readStatus === 'NOT_OPENED')?.[0]?._count ?? 0, - [SigningStatus.SIGNED]: results.filter((r) => r.signingStatus === 'SIGNED')?.[0]?._count ?? 0, - [SigningStatus.NOT_SIGNED]: - results.filter((r) => r.signingStatus === 'NOT_SIGNED')?.[0]?._count ?? 0, - [SendStatus.SENT]: results.filter((r) => r.sendStatus === 'SENT')?.[0]?._count ?? 0, - [SendStatus.NOT_SENT]: results.filter((r) => r.sendStatus === 'NOT_SENT')?.[0]?._count ?? 0, + const stats = { + TOTAL_RECIPIENTS: 0, + [ReadStatus.OPENED]: 0, + [ReadStatus.NOT_OPENED]: 0, + [SigningStatus.SIGNED]: 0, + [SigningStatus.NOT_SIGNED]: 0, + [SendStatus.SENT]: 0, + [SendStatus.NOT_SENT]: 0, }; + results.forEach((result) => { + const { readStatus, signingStatus, sendStatus, _count } = result; + stats[readStatus] += _count; + stats[signingStatus] += _count; + stats[sendStatus] += _count; + stats.TOTAL_RECIPIENTS += _count; + }); + return stats; };