diff --git a/src/routes/game/[id]/+page.server.ts b/src/routes/game/[id]/+page.server.ts index fbd5ed8..1f4834c 100644 --- a/src/routes/game/[id]/+page.server.ts +++ b/src/routes/game/[id]/+page.server.ts @@ -1,35 +1,24 @@ import { error } from '@sveltejs/kit'; +import prisma from '$lib/prisma.js'; import { boardGameApi } from '../../api'; -export const load = async ({ params, setHeaders }) => { - const queryParams = { - ids: `${params?.id}`, - fields: - 'id,name,price,min_age,min_players,max_players,thumb_url,playtime,min_playtime,max_playtime,min_age,description,year_published,url,image_url' - }; - - const response = await boardGameApi('get', `search`, queryParams); - - if (response.status === 200) { - const gameResponse = await response.json(); - - setHeaders({ - 'Cache-Control': 'max-age=3600' +export const load = async ({ params, setHeaders, locals }) => { + try { + const { user } = locals; + const { id } = params; + const game = await prisma.game.findUnique({ + where: { + id + } }); - - const game = gameResponse?.games[0]; - if (game.min_players) { - game.players = `${game.min_players}-${game.max_players}`; - } - - if (game.min_playtime) { - game.playtime = `${game.min_playtime}-${game.max_playtime}`; - } - + console.log('found game', game); return { - game + game, + user }; + } catch (error) { + console.log(error); } - throw error(response.status, 'not found'); + throw error(404, 'not found'); }; diff --git a/src/routes/game/[id]/+page.svelte b/src/routes/game/[id]/+page.svelte index 08906ae..6d4b9a5 100644 --- a/src/routes/game/[id]/+page.svelte +++ b/src/routes/game/[id]/+page.svelte @@ -32,16 +32,19 @@ $: wishlistText = existsInWishlist ? 'Remove from wishlist' : 'Add to wishlist'; export let data: PageData; - let game: GameType; - $: ({ game } = data); + console.log('data', data); + // let game: GameType; + $: ({ game, user } = data); + // let game = data?.game; // export let game: GameType = data?.game; let seeMore: boolean = false; - let firstParagraphEnd = 0; - if (game?.description?.indexOf('
') > 0) { - firstParagraphEnd = game?.description?.indexOf('') + 4; - } else if (game?.description?.indexOf(' p>') > 0) { - firstParagraphEnd = game?.description?.indexOf(' p>') + 5; - } + console.log('game', game); + // let firstParagraphEnd = 0; + // if (game?.description?.indexOf('') > 0) { + // firstParagraphEnd = game?.description?.indexOf('') + 4; + // } else if (game?.description?.indexOf(' p>') > 0) { + // firstParagraphEnd = game?.description?.indexOf(' p>') + 5; + // } function onCollectionClick() { if (existsInCollection) { @@ -100,8 +103,8 @@ {#if game?.year_published}Year: {game?.year_published}
{/if} - {#if game?.players} -Players: {game.players}
+ {#if game?.min_players && game?.max_players} +Players: {game.min_players} - {game.max_players}
{/if} {#if game?.playtime}Playtime: {game.playtime} minutes
@@ -109,54 +112,55 @@ {#if game?.min_age}Minimum Age: {game.min_age}
{/if} - {#if +game?.price !== 0.0} -Price: ${game?.price}
- {/if}