From 3d9bf1fb67e4e7c570ee7ba7f59c9e1007d2ea00 Mon Sep 17 00:00:00 2001 From: Timur Ercan Date: Tue, 14 Feb 2023 11:12:07 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- apps/web/pages/documents/[id]/index.tsx | 24 +++++++++++++----------- packages/lib/query/getDocument.ts | 2 +- 2 files changed, 14 insertions(+), 12 deletions(-) diff --git a/apps/web/pages/documents/[id]/index.tsx b/apps/web/pages/documents/[id]/index.tsx index b688a9c73..08c05acfa 100644 --- a/apps/web/pages/documents/[id]/index.tsx +++ b/apps/web/pages/documents/[id]/index.tsx @@ -114,21 +114,23 @@ export async function getServerSideProps(context: any) { const { id: documentId } = context.query; - const document: PrismaDocument = await getDocument( - +documentId, - context.req, - context.res - ); + try { + const document: PrismaDocument = await getDocument( + +documentId, + context.req, + context.res + ); + } catch (error) { + if (!document) { + return { + notFound: true, + }; + } + } // todo optimize querys // todo no intersection groups - if (!document) { - return { - notFound: true, - }; - } - return { props: { document: document, diff --git a/packages/lib/query/getDocument.ts b/packages/lib/query/getDocument.ts index d19555f62..f922f4c28 100644 --- a/packages/lib/query/getDocument.ts +++ b/packages/lib/query/getDocument.ts @@ -12,7 +12,7 @@ export const getDocument = async ( if (!documentId) Promise.reject("No documentId"); if (!req || !res) Promise.reject("No res or req"); - const document: PrismaDocument = await prisma.document.findFirst({ + const document: PrismaDocument = await prisma.document.findFirstOrThrow({ where: { id: documentId, userId: user.id,