From ccfa7771a5d9c562f5bf987ac371c342249c3ef5 Mon Sep 17 00:00:00 2001 From: Ste Vaidis Date: Fri, 17 Feb 2023 22:36:46 +0200 Subject: [PATCH] new --- app/restaurant/[slug]/page.tsx | 38 +++++++++++++++++++++++++++++++++- 1 file changed, 37 insertions(+), 1 deletion(-) diff --git a/app/restaurant/[slug]/page.tsx b/app/restaurant/[slug]/page.tsx index a024fd3..f984350 100644 --- a/app/restaurant/[slug]/page.tsx +++ b/app/restaurant/[slug]/page.tsx @@ -1,3 +1,4 @@ +import { PrismaClient } from "@prisma/client"; import Description from "./components/Description"; import Header from "./components/Header"; import Images from "./components/Images"; @@ -7,7 +8,42 @@ import RestaurantNavBar from "./components/RestaurantNavBar"; import Reviews from "./components/Reviews"; import Title from "./components/Title"; -export default function RestaurantDetails() { +interface Restaurant { + id: number; + name: string; + images: string[]; + description: string; + slug: string; +} +const prisma = new PrismaClient(); + +const fetchRestaurantBySlug = async (slug: string): Promise => { + const restaurant = await prisma.restaurant.findUnique({ + where: { + slug, + }, + select: { + id: true, + name: true, + images: true, + description: true, + slug: true, + }, + }); + + if (!restaurant) { + throw new Error() + } + + return restaurant; +}; + +export default async function RestaurantDetails({ + params, +}: { + params: { slug: string }; +}) { + const restaurant = await fetchRestaurantBySlug(params.slug); return ( <>