diff --git a/src/routes/(app)/game/[id]/+page.server.ts b/src/routes/(app)/game/[id]/+page.server.ts index 8e8b674..f132a6d 100644 --- a/src/routes/(app)/game/[id]/+page.server.ts +++ b/src/routes/(app)/game/[id]/+page.server.ts @@ -1,7 +1,15 @@ import { error } from '@sveltejs/kit'; import prisma from '$lib/prisma.js'; import type { GameType } from '$lib/types.js'; -import { createArtist, createCategory, createDesigner, createExpansion, createMechanic, createOrUpdateGame, createPublisher } from '$lib/utils/dbUtils.js'; +import { + createArtist, + createCategory, + createDesigner, + createExpansion, + createMechanic, + createOrUpdateGame, + createPublisher +} from '$lib/utils/dbUtils.js'; import { mapAPIGameToBoredGame } from '$lib/utils/gameMapper.js'; import type { Game } from '@prisma/client'; @@ -18,7 +26,12 @@ export const load = async ({ params, setHeaders, locals, fetch }) => { designers: true, publishers: true, mechanics: true, - categories: true + categories: true, + expansions: { + include: { + base_game: true + } + } } }); console.log('found game', game); @@ -28,7 +41,10 @@ export const load = async ({ params, setHeaders, locals, fetch }) => { } const currentDate = new Date(); - if (game.last_sync_at === null || currentDate.getDate() - game.last_sync_at.getDate() > 7 * 24 * 60 * 60 * 1000) { + if ( + game.last_sync_at === null || + currentDate.getDate() - game.last_sync_at.getDate() > 7 * 24 * 60 * 60 * 1000 + ) { await syncGameAndConnectedData(game, fetch); } @@ -62,6 +78,8 @@ export const load = async ({ params, setHeaders, locals, fetch }) => { }); } + console.log('Returning game', game); + return { game, user, @@ -119,10 +137,22 @@ async function syncGameAndConnectedData(game: Game, eventFetch: Function) { console.log('Inbound?', externalExpansion.inbound); if (externalExpansion?.inbound === true) { expansion = await createExpansion(game, externalExpansion, false, eventFetch); + await prisma.game.update({ + where: { + external_id: externalExpansion.id + }, + data: { + expansions: { + connect: { + id: expansion.id + } + } + } + }) } else { expansion = await createExpansion(game, externalExpansion, true, eventFetch); + expansions.push({ id: expansion.id }); } - expansions.push({ id: expansion.id }); } let boredGame = mapAPIGameToBoredGame(externalGame); @@ -135,4 +165,4 @@ async function syncGameAndConnectedData(game: Game, eventFetch: Function) { boredGame.expansions = expansions; return createOrUpdateGame(boredGame); } -} \ No newline at end of file +} diff --git a/src/routes/(app)/game/[id]/+page.svelte b/src/routes/(app)/game/[id]/+page.svelte index c81e6a4..63361b6 100644 --- a/src/routes/(app)/game/[id]/+page.svelte +++ b/src/routes/(app)/game/[id]/+page.svelte @@ -11,8 +11,8 @@ $: existsInCollection = $collectionStore.find((item: SavedGameType) => item.id === game.id); $: existsInWishlist = $wishlistStore.find((item: SavedGameType) => item.id === game.id); - $: collectionText = existsInCollection ? 'Remove from collection' : 'Add to collection'; - $: wishlistText = existsInWishlist ? 'Remove from wishlist' : 'Add to wishlist'; + // $: collectionText = existsInCollection ? 'Remove from collection' : 'Add to collection'; + // $: wishlistText = existsInWishlist ? 'Remove from wishlist' : 'Add to wishlist'; export let data: PageData; console.log('data', data); @@ -67,6 +67,24 @@ {/if} +
+

Categories

+ {#each game?.categories as category} + {category.name} + {/each} +
+
+

Mechanics

+ {#each game?.mechanics as mechanic} + {mechanic.name} + {/each} +
+
+

Expansions

+ {#each game?.expansions as expansions} + {expansions?.base_game?.name} + {/each} +
{@html game?.description}