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('') > 0) { - firstParagraphEnd = game?.description?.indexOf('') + 5; - } + console.log('game', game); + // let firstParagraphEnd = 0; + // if (game?.description?.indexOf('

') > 0) { + // firstParagraphEnd = game?.description?.indexOf('

') + 4; + // } else if (game?.description?.indexOf('') > 0) { + // firstParagraphEnd = game?.description?.indexOf('') + 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} Board Game Atlas -
- - -
+ {#if user?.username} +
+ + +
+ {:else} + + Sign Up or Sign In to collect this game + + {/if} -{#if firstParagraphEnd > 0} -
- {@html game?.description?.substring(0, firstParagraphEnd)} -
- {#if game?.description?.substring(firstParagraphEnd + 1) !== ''} -
- {#if seeMore} -
- {@html game?.description?.substring(firstParagraphEnd + 1)} -
- {/if} - +{#if game?.description_preview} + {#if !seeMore} +
+ {`${game?.description_preview.substring(0, 250)}...`}
{/if} + {#if seeMore} +
+ {@html game?.description} +
+ {/if} + {:else}
diff --git a/src/routes/search/+page.server.ts b/src/routes/search/+page.server.ts index c0e81cf..4255519 100644 --- a/src/routes/search/+page.server.ts +++ b/src/routes/search/+page.server.ts @@ -27,7 +27,7 @@ async function searchForGames(urlQueryParams: SearchQuery) { lte: urlQueryParams?.max_playtime || 5000 }, min_age: { - gte: urlQueryParams?.min_age || 130 + gte: urlQueryParams?.min_age || 0 } }, skip: urlQueryParams?.skip, @@ -79,7 +79,7 @@ async function searchForGames(urlQueryParams: SearchQuery) { } else { return { totalCount: dbGames.length, - dbGames + games: dbGames }; } } catch (e) { @@ -98,6 +98,8 @@ async function createOrUpdateGame(game: GameType) { const mechanicIds = game.mechanics.map((mechanic) => ({ external_id: mechanic.id })); + console.log('categoryIds', categoryIds); + console.log('mechanicIds', mechanicIds); return await prisma.game.upsert({ where: { external_id: game.id @@ -154,7 +156,8 @@ async function createOrUpdateGame(game: GameType) { }, create: { external_id: game.primary_publisher.id, - name: game.primary_publisher.name + name: game.primary_publisher.name, + slug: kebabCase(game.primary_publisher.name) } } },