fix getReports for website, user, team

This commit is contained in:
Francis Cao 2024-06-03 12:26:03 -07:00
parent 111c93be20
commit d40807e672
3 changed files with 29 additions and 8 deletions

View File

@ -2,8 +2,11 @@
import { Metadata } from 'next'; import { Metadata } from 'next';
import ReportsHeader from './ReportsHeader'; import ReportsHeader from './ReportsHeader';
import ReportsDataTable from './ReportsDataTable'; import ReportsDataTable from './ReportsDataTable';
import { useTeamUrl } from 'components/hooks';
export default function ReportsPage() {
const { teamId } = useTeamUrl();
export default function ReportsPage({ teamId }: { teamId: string }) {
return ( return (
<> <>
<ReportsHeader /> <ReportsHeader />

View File

@ -1,8 +1,8 @@
import ReportsPage from './ReportsPage'; import ReportsPage from './ReportsPage';
import { Metadata } from 'next'; import { Metadata } from 'next';
export default function ({ params: { teamId } }: { params: { teamId: string } }) { export default function () {
return <ReportsPage teamId={teamId} />; return <ReportsPage />;
} }
export const metadata: Metadata = { export const metadata: Metadata = {

View File

@ -66,11 +66,29 @@ export default async (
const data = await getReports( const data = await getReports(
{ {
where: { where: {
userId: !teamId && !websiteId ? userId : undefined, OR: [
websiteId, ...(websiteId ? [{ websiteId }] : []),
website: { ...(teamId
teamId, ? [
}, {
website: {
deletedAt: null,
teamId,
},
},
]
: []),
...(userId
? [
{
website: {
deletedAt: null,
userId,
},
},
]
: []),
],
}, },
include: { include: {
website: { website: {