From abe4f129c410f8a5b6d5fe226eeed06e492fe03d Mon Sep 17 00:00:00 2001 From: Bradley Shellnut Date: Wed, 17 Apr 2024 10:56:33 -0700 Subject: [PATCH] Fixing schema import for new pages. --- .../collections/[id]/+page.server.ts | 41 ++++----- .../(protected)/collections/[id]/+page.svelte | 86 +++++++++++++++++++ .../wishlists/[id]/+page.server.ts | 41 ++++----- .../(protected)/wishlists/[id]/+page.svelte | 48 +++++++++++ 4 files changed, 176 insertions(+), 40 deletions(-) diff --git a/src/routes/(app)/(protected)/collections/[id]/+page.server.ts b/src/routes/(app)/(protected)/collections/[id]/+page.server.ts index 18b376d..579c1e2 100644 --- a/src/routes/(app)/(protected)/collections/[id]/+page.server.ts +++ b/src/routes/(app)/(protected)/collections/[id]/+page.server.ts @@ -6,7 +6,7 @@ import { redirect } from 'sveltekit-flash-message/server'; import { modifyListGameSchema } from '$lib/validations/zod-schemas'; import db from '$lib/drizzle.js'; import { notSignedInMessage } from '$lib/flashMessages.js'; -import { games, wishlist_items, wishlists } from '../../../../schema.js'; +import { games, wishlist_items, wishlists } from '../../../../../schema.js'; export async function load(event) { const { params, locals } = event; @@ -18,7 +18,7 @@ export async function load(event) { try { const wishlist = await db.query.wishlists.findFirst({ - where: eq(wishlists.user_id, locals.user.id) + where: eq(wishlists.user_id, locals.user.id), }); if (!wishlist) { @@ -32,16 +32,16 @@ export async function load(event) { columns: { id: true, name: true, - thumb_url: true - } - } - } + thumb_url: true, + }, + }, + }, }); console.log('wishlist', wishlist); return { - items + items, }; } catch (e) { console.error(e); @@ -61,7 +61,7 @@ export const actions: Actions = { } const game = await db.query.games.findFirst({ - where: eq(games.id, form.data.id) + where: eq(games.id, form.data.id), }); if (!game) { @@ -76,7 +76,7 @@ export const actions: Actions = { if (game) { const wishlist = await db.query.wishlists.findFirst({ - where: eq(wishlists.user_id, locals.user.id) + where: eq(wishlists.user_id, locals.user.id), }); if (!wishlist) { @@ -85,13 +85,13 @@ export const actions: Actions = { } await db.insert(wishlist_items).values({ - game_id: game.id, - wishlist_id: wishlist.id + game_id: game.id, + wishlist_id: wishlist.id, }); } return { - form + form, }; } catch (e) { console.error(e); @@ -124,7 +124,7 @@ export const actions: Actions = { } const game = await db.query.games.findFirst({ - where: eq(games.id, form.data.id) + where: eq(games.id, form.data.id), }); if (!game) { @@ -139,7 +139,7 @@ export const actions: Actions = { if (game) { const wishlist = await db.query.wishlists.findFirst({ - where: eq(wishlists.user_id, locals.user.id) + where: eq(wishlists.user_id, locals.user.id), }); if (!wishlist) { @@ -147,18 +147,19 @@ export const actions: Actions = { return error(404, 'Wishlist not found'); } - await db.delete(wishlist_items).where(and( - eq(wishlist_items.wishlist_id, wishlist.id), - eq(wishlist_items.game_id, game.id) - )); + await db + .delete(wishlist_items) + .where( + and(eq(wishlist_items.wishlist_id, wishlist.id), eq(wishlist_items.game_id, game.id)), + ); } return { - form + form, }; } catch (e) { console.error(e); return error(500, 'Something went wrong'); } - } + }, }; diff --git a/src/routes/(app)/(protected)/collections/[id]/+page.svelte b/src/routes/(app)/(protected)/collections/[id]/+page.svelte index e69de29..063f830 100644 --- a/src/routes/(app)/(protected)/collections/[id]/+page.svelte +++ b/src/routes/(app)/(protected)/collections/[id]/+page.svelte @@ -0,0 +1,86 @@ + + + + Your Collection | Bored Game + + +

Your Collection

+ + +
+
+ {#if collectionItems.length === 0} +

No games in your collection

+ {:else} + {#each collectionItems as game (game.game_id)} + + {/each} + {/if} +
+ +
+ + diff --git a/src/routes/(app)/(protected)/wishlists/[id]/+page.server.ts b/src/routes/(app)/(protected)/wishlists/[id]/+page.server.ts index 18b376d..579c1e2 100644 --- a/src/routes/(app)/(protected)/wishlists/[id]/+page.server.ts +++ b/src/routes/(app)/(protected)/wishlists/[id]/+page.server.ts @@ -6,7 +6,7 @@ import { redirect } from 'sveltekit-flash-message/server'; import { modifyListGameSchema } from '$lib/validations/zod-schemas'; import db from '$lib/drizzle.js'; import { notSignedInMessage } from '$lib/flashMessages.js'; -import { games, wishlist_items, wishlists } from '../../../../schema.js'; +import { games, wishlist_items, wishlists } from '../../../../../schema.js'; export async function load(event) { const { params, locals } = event; @@ -18,7 +18,7 @@ export async function load(event) { try { const wishlist = await db.query.wishlists.findFirst({ - where: eq(wishlists.user_id, locals.user.id) + where: eq(wishlists.user_id, locals.user.id), }); if (!wishlist) { @@ -32,16 +32,16 @@ export async function load(event) { columns: { id: true, name: true, - thumb_url: true - } - } - } + thumb_url: true, + }, + }, + }, }); console.log('wishlist', wishlist); return { - items + items, }; } catch (e) { console.error(e); @@ -61,7 +61,7 @@ export const actions: Actions = { } const game = await db.query.games.findFirst({ - where: eq(games.id, form.data.id) + where: eq(games.id, form.data.id), }); if (!game) { @@ -76,7 +76,7 @@ export const actions: Actions = { if (game) { const wishlist = await db.query.wishlists.findFirst({ - where: eq(wishlists.user_id, locals.user.id) + where: eq(wishlists.user_id, locals.user.id), }); if (!wishlist) { @@ -85,13 +85,13 @@ export const actions: Actions = { } await db.insert(wishlist_items).values({ - game_id: game.id, - wishlist_id: wishlist.id + game_id: game.id, + wishlist_id: wishlist.id, }); } return { - form + form, }; } catch (e) { console.error(e); @@ -124,7 +124,7 @@ export const actions: Actions = { } const game = await db.query.games.findFirst({ - where: eq(games.id, form.data.id) + where: eq(games.id, form.data.id), }); if (!game) { @@ -139,7 +139,7 @@ export const actions: Actions = { if (game) { const wishlist = await db.query.wishlists.findFirst({ - where: eq(wishlists.user_id, locals.user.id) + where: eq(wishlists.user_id, locals.user.id), }); if (!wishlist) { @@ -147,18 +147,19 @@ export const actions: Actions = { return error(404, 'Wishlist not found'); } - await db.delete(wishlist_items).where(and( - eq(wishlist_items.wishlist_id, wishlist.id), - eq(wishlist_items.game_id, game.id) - )); + await db + .delete(wishlist_items) + .where( + and(eq(wishlist_items.wishlist_id, wishlist.id), eq(wishlist_items.game_id, game.id)), + ); } return { - form + form, }; } catch (e) { console.error(e); return error(500, 'Something went wrong'); } - } + }, }; diff --git a/src/routes/(app)/(protected)/wishlists/[id]/+page.svelte b/src/routes/(app)/(protected)/wishlists/[id]/+page.svelte index e69de29..12ea5c4 100644 --- a/src/routes/(app)/(protected)/wishlists/[id]/+page.svelte +++ b/src/routes/(app)/(protected)/wishlists/[id]/+page.svelte @@ -0,0 +1,48 @@ + + + + {`Your Wishlist | Bored Game`} + + +

Your wishlist

+ +
+ {#if items.length > 0} + {#each items as item (item.id)} + + {/each} + {:else} +

Sorry no games found!

+ {/if} +
+ + \ No newline at end of file