From d40807e6727b845fbf610bae844a51689179246a Mon Sep 17 00:00:00 2001 From: Francis Cao Date: Mon, 3 Jun 2024 12:26:03 -0700 Subject: [PATCH] fix getReports for website, user, team --- src/app/(main)/reports/ReportsPage.tsx | 5 ++++- src/app/(main)/reports/page.tsx | 4 ++-- src/pages/api/reports/index.ts | 28 +++++++++++++++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/app/(main)/reports/ReportsPage.tsx b/src/app/(main)/reports/ReportsPage.tsx index a76a6a47..5b031cfa 100644 --- a/src/app/(main)/reports/ReportsPage.tsx +++ b/src/app/(main)/reports/ReportsPage.tsx @@ -2,8 +2,11 @@ import { Metadata } from 'next'; import ReportsHeader from './ReportsHeader'; import ReportsDataTable from './ReportsDataTable'; +import { useTeamUrl } from 'components/hooks'; + +export default function ReportsPage() { + const { teamId } = useTeamUrl(); -export default function ReportsPage({ teamId }: { teamId: string }) { return ( <> diff --git a/src/app/(main)/reports/page.tsx b/src/app/(main)/reports/page.tsx index 4b495aca..ef4e56ad 100644 --- a/src/app/(main)/reports/page.tsx +++ b/src/app/(main)/reports/page.tsx @@ -1,8 +1,8 @@ import ReportsPage from './ReportsPage'; import { Metadata } from 'next'; -export default function ({ params: { teamId } }: { params: { teamId: string } }) { - return ; +export default function () { + return ; } export const metadata: Metadata = { diff --git a/src/pages/api/reports/index.ts b/src/pages/api/reports/index.ts index 186a1821..f9d4cca4 100644 --- a/src/pages/api/reports/index.ts +++ b/src/pages/api/reports/index.ts @@ -66,11 +66,29 @@ export default async ( const data = await getReports( { where: { - userId: !teamId && !websiteId ? userId : undefined, - websiteId, - website: { - teamId, - }, + OR: [ + ...(websiteId ? [{ websiteId }] : []), + ...(teamId + ? [ + { + website: { + deletedAt: null, + teamId, + }, + }, + ] + : []), + ...(userId + ? [ + { + website: { + deletedAt: null, + userId, + }, + }, + ] + : []), + ], }, include: { website: {