diff --git a/src/lib/utils/dbUtils.ts b/src/lib/utils/dbUtils.ts index 8940c95..6fa7eaa 100644 --- a/src/lib/utils/dbUtils.ts +++ b/src/lib/utils/dbUtils.ts @@ -1,10 +1,9 @@ -import prisma from "$lib/prisma"; -import type { GameType } from "$lib/types"; -import type { Game } from "@prisma/client"; -import type { BggThingDto } from "boardgamegeekclient/dist/esm/dto"; -import type { BggLinkDto } from "boardgamegeekclient/dist/esm/dto/concrete/subdto"; -import kebabCase from "just-kebab-case"; -import { mapAPIGameToBoredGame } from "./gameMapper"; +import type { Game } from '@prisma/client'; +import kebabCase from 'just-kebab-case'; +import type { BggLinkDto } from 'boardgamegeekclient/dist/esm/dto/concrete/subdto'; +import prisma from '$lib/prisma'; +import type { GameType } from '$lib/types'; +import { mapAPIGameToBoredGame } from './gameMapper'; export async function createArtist(externalArtist: BggLinkDto) { try { @@ -204,7 +203,12 @@ export async function createMechanic(externalMechanic: BggLinkDto) { } } -export async function createExpansion(game: Game, externalExpansion: BggLinkDto, gameIsExpansion: boolean, eventFetch: Function) { +export async function createExpansion( + game: Game, + externalExpansion: BggLinkDto, + gameIsExpansion: boolean, + eventFetch: Function +) { try { let dbExpansionGame = await prisma.game.findUnique({ where: { @@ -222,7 +226,9 @@ export async function createExpansion(game: Game, externalExpansion: BggLinkDto, let boredGame = mapAPIGameToBoredGame(externalGame); dbExpansionGame = await createOrUpdateGameMinimal(boredGame); } else { - throw new Error(`${gameIsExpansion ? 'Base game' : 'Expansion game'} not found and failed to create.`); + throw new Error( + `${gameIsExpansion ? 'Base game' : 'Expansion game'} not found and failed to create.` + ); } } @@ -230,7 +236,10 @@ export async function createExpansion(game: Game, externalExpansion: BggLinkDto, let baseGameId; let gameId; if (gameIsExpansion) { - console.log('External expansion is expansion. Looking for base game', JSON.stringify(game, null, 2)); + console.log( + 'External expansion is expansion. Looking for base game', + JSON.stringify(game, null, 2) + ); dbExpansion = await prisma.expansion.findFirst({ where: { game_id: dbExpansionGame.id @@ -244,7 +253,10 @@ export async function createExpansion(game: Game, externalExpansion: BggLinkDto, baseGameId = game.id; gameId = dbExpansionGame.id; } else { - console.log('External Expansion is base game. Looking for expansion', JSON.stringify(game, null, 2)); + console.log( + 'External Expansion is base game. Looking for expansion', + JSON.stringify(game, null, 2) + ); dbExpansion = await prisma.expansion.findFirst({ where: { base_game_id: dbExpansionGame.id diff --git a/src/routes/(app)/(protected)/collection/+page.server.ts b/src/routes/(app)/(protected)/collection/+page.server.ts index cd0d789..1df21d5 100644 --- a/src/routes/(app)/(protected)/collection/+page.server.ts +++ b/src/routes/(app)/(protected)/collection/+page.server.ts @@ -1,7 +1,7 @@ import { error, fail, redirect } from '@sveltejs/kit'; import { setError, superValidate } from 'sveltekit-superforms/server'; import type { PageServerLoad } from '../../$types.js'; -import prisma from '$lib/prisma.js'; +import prisma from '$lib/prisma'; import { modifyListGameSchema, type ListGame } from '$lib/config/zod-schemas.js'; import type { CollectionItemWithGame } from '$lib/types.js'; import { search_schema } from '$lib/zodValidation.js'; diff --git a/src/routes/(app)/(protected)/list/+layout.server.ts b/src/routes/(app)/(protected)/list/+layout.server.ts index 4186bb7..451cb00 100644 --- a/src/routes/(app)/(protected)/list/+layout.server.ts +++ b/src/routes/(app)/(protected)/list/+layout.server.ts @@ -1,4 +1,4 @@ -import prisma from '$lib/prisma.js'; +import prisma from '$lib/prisma'; import { redirect } from '@sveltejs/kit'; export async function load({ params, locals }) { diff --git a/src/routes/(app)/(protected)/list/[id]/+page.server.ts b/src/routes/(app)/(protected)/list/[id]/+page.server.ts index 6ed96db..6492bdc 100644 --- a/src/routes/(app)/(protected)/list/[id]/+page.server.ts +++ b/src/routes/(app)/(protected)/list/[id]/+page.server.ts @@ -1,6 +1,6 @@ import { fail, redirect } from '@sveltejs/kit'; import { superValidate } from 'sveltekit-superforms/server'; -import prisma from '$lib/prisma.js'; +import prisma from '$lib/prisma'; import { list_game_request_schema } from '$lib/zodValidation'; export async function load({ params, locals }) { diff --git a/src/routes/(app)/(protected)/profile/+page.server.ts b/src/routes/(app)/(protected)/profile/+page.server.ts index ee83e21..157818c 100644 --- a/src/routes/(app)/(protected)/profile/+page.server.ts +++ b/src/routes/(app)/(protected)/profile/+page.server.ts @@ -3,7 +3,6 @@ import { message, setError, superValidate } from 'sveltekit-superforms/server'; import { userSchema } from '$lib/config/zod-schemas'; import { auth } from '$lib/server/lucia.js'; import { LuciaError } from 'lucia'; -// import prisma from '$lib/prisma.js'; const profileSchema = userSchema.pick({ firstName: true, diff --git a/src/routes/(app)/(protected)/wishlist/+page.server.ts b/src/routes/(app)/(protected)/wishlist/+page.server.ts index 0d0ba86..e8e1931 100644 --- a/src/routes/(app)/(protected)/wishlist/+page.server.ts +++ b/src/routes/(app)/(protected)/wishlist/+page.server.ts @@ -1,7 +1,6 @@ import { error, redirect } from '@sveltejs/kit'; import { superValidate } from 'sveltekit-superforms/server'; -import prisma from '$lib/prisma.js'; -import { list_game_request_schema } from '$lib/zodValidation'; +import prisma from '$lib/prisma'; import { modifyListGameSchema } from '$lib/config/zod-schemas.js'; export async function load({ params, locals }) { diff --git a/src/routes/(app)/game/[id]/+page.server.ts b/src/routes/(app)/game/[id]/+page.server.ts index f132a6d..e672812 100644 --- a/src/routes/(app)/game/[id]/+page.server.ts +++ b/src/routes/(app)/game/[id]/+page.server.ts @@ -1,6 +1,5 @@ import { error } from '@sveltejs/kit'; -import prisma from '$lib/prisma.js'; -import type { GameType } from '$lib/types.js'; +import prisma from '$lib/prisma'; import { createArtist, createCategory, diff --git a/src/routes/(app)/search/+page.server.ts b/src/routes/(app)/search/+page.server.ts index b15806f..a021964 100644 --- a/src/routes/(app)/search/+page.server.ts +++ b/src/routes/(app)/search/+page.server.ts @@ -1,8 +1,6 @@ import { error } from '@sveltejs/kit'; import { superValidate } from 'sveltekit-superforms/server'; import kebabCase from 'just-kebab-case'; -import { BOARD_GAME_ATLAS_CLIENT_ID } from '$env/static/private'; -import prisma from '$lib/prisma.js'; import type { GameType, SearchQuery } from '$lib/types'; import { mapAPIGameToBoredGame } from '$lib/utils/gameMapper.js'; import { search_schema } from '$lib/zodValidation'; @@ -141,6 +139,17 @@ export const load: PageServerLoad = async ({ fetch, url }) => { // fields: ('id,name,min_age,min_players,max_players,thumb_url,min_playtime,max_playtime,min_age,description'); try { + if (form.data?.q === '') { + return { + form, + searchData: { + totalCount: 0, + games: [], + wishlists: [] + } + }; + } + if (form.data?.minAge) { if (form.data?.exactMinAge) { queryParams.min_age = form.data?.minAge; @@ -175,7 +184,8 @@ export const load: PageServerLoad = async ({ fetch, url }) => { return { form, // modifyListForm, - searchData + searchData, + wishlists: [] }; } catch (e) { console.log(`Error searching board games ${e}`); @@ -196,7 +206,6 @@ export const actions = { const queryParams: SearchQuery = { order_by: 'rank', ascending: false, - client_id: BOARD_GAME_ATLAS_CLIENT_ID, random: true, fields: 'id,name,min_age,min_players,max_players,thumb_url,min_playtime,max_playtime,min_age,description' diff --git a/src/routes/(auth)/login/+page.server.ts b/src/routes/(auth)/login/+page.server.ts index cdad34c..a82dd9d 100644 --- a/src/routes/(auth)/login/+page.server.ts +++ b/src/routes/(auth)/login/+page.server.ts @@ -2,7 +2,7 @@ import { fail } from '@sveltejs/kit'; import { setError, superValidate } from 'sveltekit-superforms/server'; import { redirect } from 'sveltekit-flash-message/server'; import { auth } from '$lib/server/lucia'; -import prisma from '$lib/prisma.js'; +import prisma from '$lib/prisma'; import { userSchema } from '$lib/config/zod-schemas'; const signInSchema = userSchema.pick({ diff --git a/src/routes/(auth)/sign-up/+page.server.ts b/src/routes/(auth)/sign-up/+page.server.ts index ca584ee..bbccd47 100644 --- a/src/routes/(auth)/sign-up/+page.server.ts +++ b/src/routes/(auth)/sign-up/+page.server.ts @@ -5,7 +5,7 @@ import { LuciaError } from 'lucia'; import { auth } from '$lib/server/lucia'; import { userSchema } from '$lib/config/zod-schemas'; import { add_user_to_role } from '$server/roles'; -import prisma from '$lib/prisma.js'; +import prisma from '$lib/prisma'; import { Schema } from 'zod'; import type { Message } from '$lib/types.js'; diff --git a/src/routes/api/collection/[id]/search/+server.ts b/src/routes/api/collection/[id]/search/+server.ts index 2405e33..fef456e 100644 --- a/src/routes/api/collection/[id]/search/+server.ts +++ b/src/routes/api/collection/[id]/search/+server.ts @@ -1,5 +1,5 @@ import { error, json } from '@sveltejs/kit'; -import prisma from '$lib/prisma.js'; +import prisma from '$lib/prisma'; import type { CollectionItemWithGame } from '$lib/types.js'; // Search a user's collection diff --git a/src/routes/api/game/search/+server.ts b/src/routes/api/game/search/+server.ts index 0039808..261d7e5 100644 --- a/src/routes/api/game/search/+server.ts +++ b/src/routes/api/game/search/+server.ts @@ -1,6 +1,6 @@ import { error, json } from '@sveltejs/kit'; import { Prisma } from '@prisma/client'; -import prisma from '$lib/prisma.js'; +import prisma from '$lib/prisma'; // Search a user's collection export const GET = async ({ url }) => { diff --git a/src/routes/api/wishlist/[id]/search/+server.ts b/src/routes/api/wishlist/[id]/search/+server.ts index 2405e33..fef456e 100644 --- a/src/routes/api/wishlist/[id]/search/+server.ts +++ b/src/routes/api/wishlist/[id]/search/+server.ts @@ -1,5 +1,5 @@ import { error, json } from '@sveltejs/kit'; -import prisma from '$lib/prisma.js'; +import prisma from '$lib/prisma'; import type { CollectionItemWithGame } from '$lib/types.js'; // Search a user's collection diff --git a/src/search/actions.ts b/src/search/actions.ts index 6ea4e9b..b1e9e2d 100644 --- a/src/search/actions.ts +++ b/src/search/actions.ts @@ -1,5 +1,4 @@ import { invalid, type RequestEvent } from '@sveltejs/kit'; -import { BOARD_GAME_ATLAS_CLIENT_ID } from '$env/static/private'; import type { GameType, SearchQuery } from '$lib/types'; import { mapAPIGameToBoredGame } from '$lib/utils/gameMapper'; @@ -18,8 +17,6 @@ export const Games: Actions = { ascending: false, limit: 10, skip: 0, - client_id: BOARD_GAME_ATLAS_CLIENT_ID, - fuzzy_match: true, name: '' };