mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Fixing prisma issues by removing from locals and just using as singleton import. Upgrading libraries.
This commit is contained in:
parent
7d334f9cb7
commit
4e300a72a1
24 changed files with 1636 additions and 1812 deletions
38
package.json
38
package.json
|
|
@ -29,43 +29,43 @@
|
|||
"@melt-ui/pp": "^0.1.2",
|
||||
"@playwright/test": "^1.37.0",
|
||||
"@resvg/resvg-js": "^2.4.1",
|
||||
"@sveltejs/adapter-auto": "^1.0.3",
|
||||
"@sveltejs/adapter-vercel": "^1.0.6",
|
||||
"@sveltejs/kit": "^1.25.2",
|
||||
"@sveltejs/adapter-auto": "^2.1.1",
|
||||
"@sveltejs/adapter-vercel": "^3.0.3",
|
||||
"@sveltejs/kit": "^1.27.2",
|
||||
"@types/cookie": "^0.5.1",
|
||||
"@types/node": "^18.17.5",
|
||||
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
||||
"@typescript-eslint/parser": "^5.62.0",
|
||||
"@typescript-eslint/eslint-plugin": "^6.7.5",
|
||||
"@typescript-eslint/parser": "^6.7.5",
|
||||
"autoprefixer": "^10.4.15",
|
||||
"eslint": "^8.47.0",
|
||||
"eslint-config-prettier": "^8.10.0",
|
||||
"eslint-config-prettier": "^9.0.0",
|
||||
"eslint-plugin-svelte": "^2.32.4",
|
||||
"just-clone": "^6.2.0",
|
||||
"just-debounce-it": "^3.2.0",
|
||||
"postcss": "^8.4.30",
|
||||
"postcss": "^8.4.31",
|
||||
"postcss-import": "^15.1.0",
|
||||
"postcss-load-config": "^4.0.1",
|
||||
"postcss-preset-env": "^8.5.1",
|
||||
"prettier": "^2.8.8",
|
||||
"prettier-plugin-svelte": "^2.10.1",
|
||||
"prisma": "^5.4.2",
|
||||
"postcss-preset-env": "^9.3.0",
|
||||
"prettier": "^3.0.3",
|
||||
"prettier-plugin-svelte": "^3.0.3",
|
||||
"prisma": "^5.3.1",
|
||||
"sass": "^1.65.1",
|
||||
"satori": "^0.10.4",
|
||||
"satori-html": "^0.3.2",
|
||||
"svelte": "^4.2.1",
|
||||
"svelte-check": "^3.5.0",
|
||||
"svelte": "^4.2.2",
|
||||
"svelte-check": "^3.5.2",
|
||||
"svelte-meta-tags": "^3.0.4",
|
||||
"svelte-preprocess": "^5.0.4",
|
||||
"svelte-sequential-preprocessor": "^2.0.1",
|
||||
"sveltekit-flash-message": "^2.2.1",
|
||||
"sveltekit-superforms": "^1.7.2",
|
||||
"sveltekit-superforms": "^1.9.0",
|
||||
"tailwindcss": "^3.3.3",
|
||||
"ts-node": "^10.9.1",
|
||||
"tslib": "^2.6.1",
|
||||
"typescript": "^5.1.6",
|
||||
"vite": "^4.4.9",
|
||||
"vitest": "^0.25.3",
|
||||
"zod": "^3.22.2"
|
||||
"vitest": "^0.34.6",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
"type": "module",
|
||||
"engines": {
|
||||
|
|
@ -82,8 +82,8 @@
|
|||
"@lukeed/uuid": "^2.0.1",
|
||||
"@melt-ui/svelte": "^0.50.1",
|
||||
"@paralleldrive/cuid2": "^2.2.2",
|
||||
"@prisma/client": "^5.4.2",
|
||||
"@sentry/sveltekit": "^7.74.0",
|
||||
"@prisma/client": "^5.3.1",
|
||||
"@sentry/sveltekit": "^7.77.0",
|
||||
"@types/feather-icons": "^4.29.1",
|
||||
"@vercel/og": "^0.5.13",
|
||||
"bits-ui": "^0.0.27",
|
||||
|
|
@ -97,7 +97,7 @@
|
|||
"iconify-icon": "^1.0.8",
|
||||
"just-kebab-case": "^4.2.0",
|
||||
"loader": "^2.1.1",
|
||||
"lucia": "^2.7.1",
|
||||
"lucia": "^2.7.2",
|
||||
"lucide-svelte": "^0.256.1",
|
||||
"open-props": "^1.5.13",
|
||||
"radix-svelte": "^0.9.0",
|
||||
|
|
|
|||
3037
pnpm-lock.yaml
3037
pnpm-lock.yaml
File diff suppressed because it is too large
Load diff
2
src/app.d.ts
vendored
2
src/app.d.ts
vendored
|
|
@ -2,7 +2,7 @@
|
|||
// for information about these interfaces
|
||||
// and what to do when importing types
|
||||
|
||||
import type { User } from '@prisma/client';
|
||||
import type { PrismaClient, User } from '@prisma/client';
|
||||
|
||||
type User = Omit<User, 'created_at' | 'updated_at'>;
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import * as Sentry from '@sentry/sveltekit';
|
||||
import { sequence } from '@sveltejs/kit/hooks';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import type { Handle } from '@sveltejs/kit';
|
||||
import { auth } from '$lib/server/lucia';
|
||||
import { dev } from '$app/environment';
|
||||
import { auth } from '$lib/server/lucia';
|
||||
|
||||
Sentry.init({
|
||||
dsn: 'https://742e43279df93a3c4a4a78c12eb1f879@o4506057768632320.ingest.sentry.io/4506057770401792',
|
||||
|
|
@ -11,10 +10,6 @@ Sentry.init({
|
|||
environment: dev ? 'development' : 'production'
|
||||
});
|
||||
|
||||
// * START UP
|
||||
// RUNS ONCE ON FILE LOAD
|
||||
export const prisma_client = new PrismaClient();
|
||||
|
||||
export const authentication: Handle = async function ({ event, resolve }) {
|
||||
const startTimer = Date.now();
|
||||
event.locals.startTimer = startTimer;
|
||||
|
|
@ -22,9 +17,11 @@ export const authentication: Handle = async function ({ event, resolve }) {
|
|||
event.locals.auth = auth.handleRequest(event);
|
||||
if (event?.locals?.auth) {
|
||||
console.log('auth not empty');
|
||||
console.log('auth', event.locals.auth);
|
||||
try {
|
||||
const session = await event.locals.auth.validate();
|
||||
console.log('user', session?.user);
|
||||
console.log('session', JSON.stringify(session, null, 2));
|
||||
event.locals.user = session?.user;
|
||||
// if (event.route.id?.startsWith('/(protected)')) {
|
||||
// if (!user) throw redirect(302, '/sign-in');
|
||||
|
|
@ -36,23 +33,25 @@ export const authentication: Handle = async function ({ event, resolve }) {
|
|||
} else {
|
||||
console.log('auth empty');
|
||||
}
|
||||
|
||||
return await resolve(event);
|
||||
};
|
||||
|
||||
// This hook is used to pass our prisma instance to each action, load, and endpoint
|
||||
export const prisma: Handle = async function ({ event, resolve }) {
|
||||
const ip = event.request.headers.get('x-forwarded-for') as string;
|
||||
const country = event.request.headers.get('x-vercel-ip-country') as string;
|
||||
event.locals.prisma = prisma_client;
|
||||
event.locals.session = {
|
||||
...event.locals.session,
|
||||
ip,
|
||||
country
|
||||
};
|
||||
const response = await resolve(event);
|
||||
return response;
|
||||
};
|
||||
// export const prisma: Handle = async function ({ event, resolve }) {
|
||||
// try {
|
||||
// const ip = event.request.headers.get('x-forwarded-for') as string;
|
||||
// const country = event.request.headers.get('x-vercel-ip-country') as string;
|
||||
// event.locals.prisma = prisma_client;
|
||||
// event.locals.session = {
|
||||
// ...event.locals.session,
|
||||
// ip,
|
||||
// country
|
||||
// };
|
||||
// } catch (error) {
|
||||
// console.error(error);
|
||||
// }
|
||||
// return await resolve(event);
|
||||
// };
|
||||
|
||||
export const handle = sequence(sequence(Sentry.sentryHandle(), authentication, prisma));
|
||||
export const handle: Handle = sequence(sequence(Sentry.sentryHandle(), authentication));
|
||||
export const handleError = Sentry.handleErrorWithSentry();
|
||||
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { Form as FormPrimitive } from "formsnap";
|
||||
import { buttonVariants } from "$lib/components/ui/button";
|
||||
import { cn } from "@/utils";
|
||||
import { cn } from "$lib/utils";
|
||||
import { ChevronDown } from "lucide-svelte";
|
||||
import type { HTMLSelectAttributes } from "svelte/elements";
|
||||
|
||||
|
|
|
|||
4
src/lib/prisma.ts
Normal file
4
src/lib/prisma.ts
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
import { PrismaClient } from '@prisma/client'
|
||||
|
||||
const prisma = new PrismaClient()
|
||||
export default prisma
|
||||
|
|
@ -3,12 +3,14 @@ import { lucia } from 'lucia';
|
|||
import { sveltekit } from 'lucia/middleware';
|
||||
import { prisma } from '@lucia-auth/adapter-prisma';
|
||||
import { dev } from '$app/environment';
|
||||
import { PrismaClient } from '@prisma/client';
|
||||
import prisma_client from '$lib/prisma';
|
||||
|
||||
// export const prisma_client = new PrismaClient();
|
||||
|
||||
export const auth = lucia({
|
||||
env: dev ? 'DEV' : 'PROD',
|
||||
middleware: sveltekit(),
|
||||
adapter: prisma(new PrismaClient()),
|
||||
adapter: prisma(prisma_client),
|
||||
getUserAttributes: (databaseUser) => {
|
||||
return {
|
||||
username: databaseUser.username,
|
||||
|
|
|
|||
|
|
@ -1,11 +1,12 @@
|
|||
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 { mapAPIGameToBoredGame } from './gameMapper';
|
||||
|
||||
export async function createArtist(locals: App.Locals, externalArtist: BggLinkDto) {
|
||||
try {
|
||||
let dbArtist = await locals.prisma.artist.findFirst({
|
||||
let dbArtist = await prisma.artist.findFirst({
|
||||
where: {
|
||||
external_id: externalArtist.id
|
||||
},
|
||||
|
|
@ -21,7 +22,7 @@ export async function createArtist(locals: App.Locals, externalArtist: BggLinkDt
|
|||
return dbArtist;
|
||||
}
|
||||
console.log('Creating artist', JSON.stringify(externalArtist, null, 2));
|
||||
let artist = await locals.prisma.artist.create({
|
||||
let artist = await prisma.artist.create({
|
||||
data: {
|
||||
name: externalArtist.value,
|
||||
external_id: externalArtist.id,
|
||||
|
|
@ -45,7 +46,7 @@ export async function createArtist(locals: App.Locals, externalArtist: BggLinkDt
|
|||
|
||||
export async function createDesigner(locals: App.Locals, externalDesigner: BggLinkDto) {
|
||||
try {
|
||||
let dbDesigner = await locals.prisma.designer.findFirst({
|
||||
let dbDesigner = await prisma.designer.findFirst({
|
||||
where: {
|
||||
external_id: externalDesigner.id
|
||||
},
|
||||
|
|
@ -61,7 +62,7 @@ export async function createDesigner(locals: App.Locals, externalDesigner: BggLi
|
|||
return dbDesigner;
|
||||
}
|
||||
console.log('Creating designer', JSON.stringify(externalDesigner, null, 2));
|
||||
let designer = await locals.prisma.designer.create({
|
||||
let designer = await prisma.designer.create({
|
||||
data: {
|
||||
name: externalDesigner.value,
|
||||
external_id: externalDesigner.id,
|
||||
|
|
@ -85,7 +86,7 @@ export async function createDesigner(locals: App.Locals, externalDesigner: BggLi
|
|||
|
||||
export async function createPublisher(locals: App.Locals, externalPublisher: BggLinkDto) {
|
||||
try {
|
||||
let dbPublisher = await locals.prisma.publisher.findFirst({
|
||||
let dbPublisher = await prisma.publisher.findFirst({
|
||||
where: {
|
||||
external_id: externalPublisher.id
|
||||
},
|
||||
|
|
@ -101,7 +102,7 @@ export async function createPublisher(locals: App.Locals, externalPublisher: Bgg
|
|||
return dbPublisher;
|
||||
}
|
||||
console.log('Creating publisher', JSON.stringify(externalPublisher, null, 2));
|
||||
let publisher = await locals.prisma.publisher.create({
|
||||
let publisher = await prisma.publisher.create({
|
||||
data: {
|
||||
name: externalPublisher.value,
|
||||
external_id: externalPublisher.id,
|
||||
|
|
@ -125,7 +126,7 @@ export async function createPublisher(locals: App.Locals, externalPublisher: Bgg
|
|||
|
||||
export async function createCategory(locals: App.Locals, externalCategory: BggLinkDto) {
|
||||
try {
|
||||
let dbCategory = await locals.prisma.category.findFirst({
|
||||
let dbCategory = await prisma.category.findFirst({
|
||||
where: {
|
||||
external_id: externalCategory.id
|
||||
},
|
||||
|
|
@ -141,7 +142,7 @@ export async function createCategory(locals: App.Locals, externalCategory: BggLi
|
|||
return dbCategory;
|
||||
}
|
||||
console.log('Creating category', JSON.stringify(externalCategory, null, 2));
|
||||
let category = await locals.prisma.category.create({
|
||||
let category = await prisma.category.create({
|
||||
data: {
|
||||
name: externalCategory.value,
|
||||
external_id: externalCategory.id,
|
||||
|
|
@ -166,7 +167,7 @@ export async function createCategory(locals: App.Locals, externalCategory: BggLi
|
|||
|
||||
export async function createMechanic(locals: App.Locals, externalMechanic: BggLinkDto) {
|
||||
try {
|
||||
let dbMechanic = await locals.prisma.mechanic.findFirst({
|
||||
let dbMechanic = await prisma.mechanic.findFirst({
|
||||
where: {
|
||||
external_id: externalMechanic.id
|
||||
},
|
||||
|
|
@ -182,7 +183,7 @@ export async function createMechanic(locals: App.Locals, externalMechanic: BggLi
|
|||
return dbMechanic;
|
||||
}
|
||||
console.log('Creating mechanic', JSON.stringify(externalMechanic, null, 2));
|
||||
let mechanic = await locals.prisma.mechanic.upsert({
|
||||
let mechanic = await prisma.mechanic.upsert({
|
||||
where: {
|
||||
external_id: externalMechanic.id
|
||||
},
|
||||
|
|
@ -214,7 +215,7 @@ export async function createExpansion(
|
|||
eventFetch: Function
|
||||
) {
|
||||
try {
|
||||
let dbExpansionGame = await locals.prisma.game.findUnique({
|
||||
let dbExpansionGame = await prisma.game.findUnique({
|
||||
where: {
|
||||
external_id: externalExpansion.id
|
||||
}
|
||||
|
|
@ -244,7 +245,7 @@ export async function createExpansion(
|
|||
'External expansion is expansion. Looking for base game',
|
||||
JSON.stringify(game, null, 2)
|
||||
);
|
||||
dbExpansion = await locals.prisma.expansion.findFirst({
|
||||
dbExpansion = await prisma.expansion.findFirst({
|
||||
where: {
|
||||
game_id: dbExpansionGame.id
|
||||
},
|
||||
|
|
@ -261,7 +262,7 @@ export async function createExpansion(
|
|||
'External Expansion is base game. Looking for expansion',
|
||||
JSON.stringify(game, null, 2)
|
||||
);
|
||||
dbExpansion = await locals.prisma.expansion.findFirst({
|
||||
dbExpansion = await prisma.expansion.findFirst({
|
||||
where: {
|
||||
base_game_id: dbExpansionGame.id
|
||||
},
|
||||
|
|
@ -281,7 +282,7 @@ export async function createExpansion(
|
|||
}
|
||||
|
||||
console.log(`Creating expansion. baseGameId: ${baseGameId}, gameId: ${gameId}`);
|
||||
let expansion = await locals.prisma.expansion.create({
|
||||
let expansion = await prisma.expansion.create({
|
||||
data: {
|
||||
base_game_id: baseGameId,
|
||||
game_id: gameId
|
||||
|
|
@ -292,7 +293,7 @@ export async function createExpansion(
|
|||
|
||||
if (gameIsExpansion) {
|
||||
console.log('Connecting current game to expansion');
|
||||
await locals.prisma.game.update({
|
||||
await prisma.game.update({
|
||||
where: {
|
||||
id: gameId
|
||||
},
|
||||
|
|
@ -306,9 +307,9 @@ export async function createExpansion(
|
|||
});
|
||||
} else {
|
||||
console.log('Connecting current game to base game');
|
||||
await locals.prisma.game.update({
|
||||
await prisma.game.update({
|
||||
where: {
|
||||
external_id: baseGameId
|
||||
id: baseGameId
|
||||
},
|
||||
data: {
|
||||
expansions: {
|
||||
|
|
@ -330,7 +331,7 @@ export async function createExpansion(
|
|||
export async function createOrUpdateGameMinimal(locals: App.Locals, game: Game) {
|
||||
console.log('Creating or updating minimal game data', JSON.stringify(game, null, 2));
|
||||
const externalUrl = `https://boardgamegeek.com/boardgame/${game.external_id}`;
|
||||
return await locals.prisma.game.upsert({
|
||||
return await prisma.game.upsert({
|
||||
where: {
|
||||
external_id: game.external_id
|
||||
},
|
||||
|
|
@ -378,7 +379,7 @@ export async function createOrUpdateGame(locals: App.Locals, game: Game) {
|
|||
const externalUrl = `https://boardgamegeek.com/boardgame/${game.external_id}`;
|
||||
console.log('categoryIds', categoryIds);
|
||||
console.log('mechanicIds', mechanicIds);
|
||||
return await locals.prisma.game.upsert({
|
||||
return await prisma.game.upsert({
|
||||
include: {
|
||||
mechanics: true,
|
||||
publishers: true,
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { error, fail, redirect } from '@sveltejs/kit';
|
||||
import { superValidate } from 'sveltekit-superforms/server';
|
||||
import type { PageServerLoad } from '../../$types.js';
|
||||
import prisma from '$lib/prisma';
|
||||
import { modifyListGameSchema, type ListGame } from '$lib/config/zod-schemas.js';
|
||||
import { search_schema } from '$lib/zodValidation.js';
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ export const load: PageServerLoad = async ({ fetch, url, locals }) => {
|
|||
const listManageForm = await superValidate(modifyListGameSchema);
|
||||
|
||||
try {
|
||||
let collection = await locals.prisma.collection.findUnique({
|
||||
let collection = await prisma.collection.findUnique({
|
||||
where: {
|
||||
user_id: session.user.userId
|
||||
}
|
||||
|
|
@ -37,14 +38,14 @@ export const load: PageServerLoad = async ({ fetch, url, locals }) => {
|
|||
if (!collection) {
|
||||
console.log('Collection was not found');
|
||||
return fail(404, {});
|
||||
// collection = await locals.prisma.collection.create({
|
||||
// collection = await prisma.collection.create({
|
||||
// data: {
|
||||
// user_id: session.userId
|
||||
// }
|
||||
// });
|
||||
}
|
||||
|
||||
let collection_items = await locals.prisma.collectionItem.findMany({
|
||||
let collection_items = await prisma.collectionItem.findMany({
|
||||
where: {
|
||||
collection_id: collection.id
|
||||
},
|
||||
|
|
@ -108,14 +109,14 @@ export const actions = {
|
|||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
let game = await locals.prisma.game.findUnique({
|
||||
let game = await prisma.game.findUnique({
|
||||
where: {
|
||||
id: form.data.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!game) {
|
||||
// game = await locals.prisma.game.create({
|
||||
// game = await prisma.game.create({
|
||||
// data: {
|
||||
// name: form.name
|
||||
// }
|
||||
|
|
@ -125,7 +126,7 @@ export const actions = {
|
|||
}
|
||||
|
||||
if (game) {
|
||||
const collection = await locals.prisma.collection.findUnique({
|
||||
const collection = await prisma.collection.findUnique({
|
||||
where: {
|
||||
user_id: session.user.userId
|
||||
}
|
||||
|
|
@ -136,7 +137,7 @@ export const actions = {
|
|||
return error(404, 'Wishlist not found');
|
||||
}
|
||||
|
||||
await locals.prisma.collectionItem.create({
|
||||
await prisma.collectionItem.create({
|
||||
data: {
|
||||
game_id: game.id,
|
||||
collection_id: collection.id,
|
||||
|
|
@ -180,14 +181,14 @@ export const actions = {
|
|||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
let game = await locals.prisma.game.findUnique({
|
||||
let game = await prisma.game.findUnique({
|
||||
where: {
|
||||
id: form.data.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!game) {
|
||||
// game = await locals.prisma.game.create({
|
||||
// game = await prisma.game.create({
|
||||
// data: {
|
||||
// name: form.name
|
||||
// }
|
||||
|
|
@ -197,7 +198,7 @@ export const actions = {
|
|||
}
|
||||
|
||||
if (game) {
|
||||
const collection = await locals.prisma.collection.findUnique({
|
||||
const collection = await prisma.collection.findUnique({
|
||||
where: {
|
||||
user_id: session.user.userId
|
||||
}
|
||||
|
|
@ -208,7 +209,7 @@ export const actions = {
|
|||
return error(404, 'Wishlist not found');
|
||||
}
|
||||
|
||||
await locals.prisma.collectionItem.delete({
|
||||
await prisma.collectionItem.delete({
|
||||
where: {
|
||||
collection_id: collection.id,
|
||||
game_id: game.id
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { redirect } from '@sveltejs/kit';
|
||||
import prisma from '$lib/prisma';
|
||||
|
||||
export async function load({ locals }) {
|
||||
const session = await locals.auth.validate();
|
||||
|
|
@ -7,14 +8,14 @@ export async function load({ locals }) {
|
|||
}
|
||||
|
||||
try {
|
||||
let wishlists = await locals.prisma.wishlist.findMany({
|
||||
let wishlists = await prisma.wishlist.findMany({
|
||||
where: {
|
||||
user_id: session.userId
|
||||
}
|
||||
});
|
||||
|
||||
if (wishlists.length === 0) {
|
||||
const wishlist = await locals.prisma.wishlist.create({
|
||||
const wishlist = await prisma.wishlist.create({
|
||||
data: {
|
||||
user_id: session.userId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { fail, redirect } from '@sveltejs/kit';
|
||||
import { superValidate } from 'sveltekit-superforms/server';
|
||||
import prisma from '$lib/prisma';
|
||||
|
||||
export async function load({ params, locals }) {
|
||||
const session = await locals.auth.validate();
|
||||
|
|
@ -8,7 +9,7 @@ export async function load({ params, locals }) {
|
|||
}
|
||||
|
||||
try {
|
||||
let wishlist = await locals.prisma.wishlist.findUnique({
|
||||
let wishlist = await prisma.wishlist.findUnique({
|
||||
where: {
|
||||
id: params.id,
|
||||
AND: {
|
||||
|
|
@ -50,14 +51,14 @@ export const actions = {
|
|||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
let game = await locals.prisma.game.findUnique({
|
||||
let game = await prisma.game.findUnique({
|
||||
where: {
|
||||
id: form.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!game) {
|
||||
// game = await locals.prisma.game.create({
|
||||
// game = await prisma.game.create({
|
||||
// data: {
|
||||
// name: form.name
|
||||
// }
|
||||
|
|
@ -67,7 +68,7 @@ export const actions = {
|
|||
});
|
||||
}
|
||||
|
||||
const wishlist = await locals.prisma.wishlist.findUnique({
|
||||
const wishlist = await prisma.wishlist.findUnique({
|
||||
where: {
|
||||
id: params.id
|
||||
}
|
||||
|
|
@ -83,7 +84,7 @@ export const actions = {
|
|||
throw redirect(302, '/404');
|
||||
}
|
||||
|
||||
const wishlistItem = await locals.prisma.wishlistItem.create({
|
||||
const wishlistItem = await prisma.wishlistItem.create({
|
||||
data: {
|
||||
game_id: game.id,
|
||||
wishlist_id: wishlist.id
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
import { error, redirect } from '@sveltejs/kit';
|
||||
import { superValidate } from 'sveltekit-superforms/server';
|
||||
import prisma from '$lib/prisma';
|
||||
import { modifyListGameSchema } from '$lib/config/zod-schemas.js';
|
||||
|
||||
export async function load({ params, locals }) {
|
||||
|
|
@ -11,7 +12,7 @@ export async function load({ params, locals }) {
|
|||
console.log('Wishlist load User id', session.user);
|
||||
|
||||
try {
|
||||
let wishlist = await locals.prisma.wishlist.findUnique({
|
||||
let wishlist = await prisma.wishlist.findUnique({
|
||||
where: {
|
||||
user_id: session?.user?.userId
|
||||
},
|
||||
|
|
@ -57,14 +58,14 @@ export const actions = {
|
|||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
let game = await locals.prisma.game.findUnique({
|
||||
let game = await prisma.game.findUnique({
|
||||
where: {
|
||||
id: form.data.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!game) {
|
||||
// game = await locals.prisma.game.create({
|
||||
// game = await prisma.game.create({
|
||||
// data: {
|
||||
// name: form.name
|
||||
// }
|
||||
|
|
@ -74,7 +75,7 @@ export const actions = {
|
|||
}
|
||||
|
||||
if (game) {
|
||||
const wishlist = await locals.prisma.wishlist.findUnique({
|
||||
const wishlist = await prisma.wishlist.findUnique({
|
||||
where: {
|
||||
user_id: session.user.userId
|
||||
}
|
||||
|
|
@ -85,7 +86,7 @@ export const actions = {
|
|||
return error(404, 'Wishlist not found');
|
||||
}
|
||||
|
||||
await locals.prisma.wishlistItem.create({
|
||||
await prisma.wishlistItem.create({
|
||||
data: {
|
||||
game_id: game.id,
|
||||
wishlist_id: wishlist.id
|
||||
|
|
@ -128,14 +129,14 @@ export const actions = {
|
|||
throw redirect(302, '/login');
|
||||
}
|
||||
|
||||
let game = await locals.prisma.game.findUnique({
|
||||
let game = await prisma.game.findUnique({
|
||||
where: {
|
||||
id: form.data.id
|
||||
}
|
||||
});
|
||||
|
||||
if (!game) {
|
||||
// game = await locals.prisma.game.create({
|
||||
// game = await prisma.game.create({
|
||||
// data: {
|
||||
// name: form.name
|
||||
// }
|
||||
|
|
@ -145,7 +146,7 @@ export const actions = {
|
|||
}
|
||||
|
||||
if (game) {
|
||||
const wishlist = await locals.prisma.wishlist.findUnique({
|
||||
const wishlist = await prisma.wishlist.findUnique({
|
||||
where: {
|
||||
user_id: session.user.userId
|
||||
}
|
||||
|
|
@ -156,7 +157,7 @@ export const actions = {
|
|||
return error(404, 'Wishlist not found');
|
||||
}
|
||||
|
||||
await locals.prisma.wishlistItem.delete({
|
||||
await prisma.wishlistItem.delete({
|
||||
where: {
|
||||
wishlist_id: wishlist.id,
|
||||
game_id: game.id
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { error } from '@sveltejs/kit';
|
||||
import type { Game } from '@prisma/client';
|
||||
import {
|
||||
createArtist,
|
||||
createCategory,
|
||||
|
|
@ -9,13 +10,13 @@ import {
|
|||
createPublisher
|
||||
} from '$lib/utils/dbUtils.js';
|
||||
import { mapAPIGameToBoredGame } from '$lib/utils/gameMapper.js';
|
||||
import type { Game } from '@prisma/client';
|
||||
import prisma from '$lib/prisma';
|
||||
|
||||
export const load = async ({ params, locals, fetch }) => {
|
||||
try {
|
||||
const { user } = locals;
|
||||
const { id } = params;
|
||||
const game = await locals.prisma.game.findUnique({
|
||||
const game = await prisma.game.findUnique({
|
||||
where: {
|
||||
id
|
||||
},
|
||||
|
|
@ -64,7 +65,7 @@ export const load = async ({ params, locals, fetch }) => {
|
|||
let wishlist;
|
||||
let collection;
|
||||
if (user) {
|
||||
wishlist = await locals.prisma.wishlist.findUnique({
|
||||
wishlist = await prisma.wishlist.findUnique({
|
||||
where: {
|
||||
user_id: user.userId
|
||||
},
|
||||
|
|
@ -77,7 +78,7 @@ export const load = async ({ params, locals, fetch }) => {
|
|||
}
|
||||
});
|
||||
|
||||
collection = await locals.prisma.collection.findUnique({
|
||||
collection = await prisma.collection.findUnique({
|
||||
where: {
|
||||
user_id: user.userId
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,9 +1,8 @@
|
|||
import { loadFlash } from 'sveltekit-flash-message/server';
|
||||
import type { LayoutServerLoad } from './$types';
|
||||
|
||||
export const load: LayoutServerLoad = loadFlash(async ({ url, locals }) => {
|
||||
export const load: LayoutServerLoad = async ({ url, locals }) => {
|
||||
return {
|
||||
url: url.pathname,
|
||||
user: locals.user
|
||||
};
|
||||
});
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { fail } from '@sveltejs/kit';
|
||||
import { setError, superValidate } from 'sveltekit-superforms/server';
|
||||
import { redirect } from 'sveltekit-flash-message/server';
|
||||
import prisma from '$lib/prisma';
|
||||
import { auth } from '$lib/server/lucia';
|
||||
import { userSchema } from '$lib/config/zod-schemas';
|
||||
|
||||
|
|
@ -10,16 +11,22 @@ const signInSchema = userSchema.pick({
|
|||
});
|
||||
|
||||
export const load = async (event) => {
|
||||
console.log('login load event', event);
|
||||
const session = await event.locals.auth.validate();
|
||||
if (session) {
|
||||
const message = { type: 'info', message: 'You are already signed in' };
|
||||
throw redirect('/', message, event);
|
||||
}
|
||||
const form = await superValidate(event, signInSchema);
|
||||
return {
|
||||
form
|
||||
};
|
||||
try {
|
||||
console.log('login load event', event);
|
||||
const session = await event.locals.auth.validate();
|
||||
if (session) {
|
||||
const message = { type: 'info', message: 'You are already signed in' };
|
||||
throw redirect('/', message, event);
|
||||
}
|
||||
return {
|
||||
form
|
||||
};
|
||||
} catch (e) {
|
||||
fail(500, {
|
||||
form
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
export const actions = {
|
||||
|
|
@ -42,7 +49,7 @@ export const actions = {
|
|||
});
|
||||
event.locals.auth.setSession(session);
|
||||
|
||||
const user = await locals.prisma.user.findUnique({
|
||||
const user = await prisma.user.findUnique({
|
||||
where: {
|
||||
id: session.user.userId
|
||||
},
|
||||
|
|
@ -55,7 +62,7 @@ export const actions = {
|
|||
}
|
||||
});
|
||||
if (user) {
|
||||
await locals.prisma.collection.upsert({
|
||||
await prisma.collection.upsert({
|
||||
where: {
|
||||
user_id: user.id
|
||||
},
|
||||
|
|
@ -66,7 +73,7 @@ export const actions = {
|
|||
user_id: user.id
|
||||
}
|
||||
});
|
||||
await locals.prisma.wishlist.upsert({
|
||||
await prisma.wishlist.upsert({
|
||||
where: {
|
||||
user_id: user.id
|
||||
},
|
||||
|
|
|
|||
|
|
@ -32,15 +32,15 @@
|
|||
delayMs: 0,
|
||||
});
|
||||
|
||||
const flash = flashModule.getFlash(page);
|
||||
// const flash = flashModule.getFlash(page);
|
||||
|
||||
$: {
|
||||
if ($flash) {
|
||||
toast.error($flash.message, {
|
||||
duration: 5000
|
||||
});
|
||||
}
|
||||
}
|
||||
// $: {
|
||||
// if ($flash) {
|
||||
// toast.error($flash.message, {
|
||||
// duration: 5000
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
import { fail, redirect, error } from '@sveltejs/kit';
|
||||
import { superValidate } from 'sveltekit-superforms/server';
|
||||
import { LuciaError } from 'lucia';
|
||||
import prisma from '$lib/prisma';
|
||||
import { auth } from '$lib/server/lucia';
|
||||
import { userSchema } from '$lib/config/zod-schemas';
|
||||
import { add_user_to_role } from '$server/roles';
|
||||
|
|
@ -33,10 +34,10 @@ const signUpSchema = userSchema
|
|||
|
||||
export const load = async (event) => {
|
||||
console.log('sign up load event', event);
|
||||
const session = await event.locals.auth.validate();
|
||||
if (session) {
|
||||
throw redirect(302, '/');
|
||||
}
|
||||
// const session = await event.locals.auth.validate();
|
||||
// if (session) {
|
||||
// throw redirect(302, '/');
|
||||
// }
|
||||
return {
|
||||
form: await superValidate<typeof signUpSchema, Message>(event, signUpSchema)
|
||||
};
|
||||
|
|
@ -78,12 +79,12 @@ export const actions = {
|
|||
});
|
||||
console.log('signup user', user);
|
||||
add_user_to_role(user.userId, 'user');
|
||||
await locals.prisma.collection.create({
|
||||
await prisma.collection.create({
|
||||
data: {
|
||||
user_id: user.userId
|
||||
}
|
||||
});
|
||||
await locals.prisma.wishlist.create({
|
||||
await prisma.wishlist.create({
|
||||
data: {
|
||||
user_id: user.userId
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,15 +31,15 @@
|
|||
delayMs: 0,
|
||||
});
|
||||
|
||||
const flash = flashModule.getFlash(page);
|
||||
// const flash = flashModule.getFlash(page);
|
||||
|
||||
$: {
|
||||
if ($flash) {
|
||||
toast.error($flash.message, {
|
||||
duration: 5000
|
||||
});
|
||||
}
|
||||
}
|
||||
// $: {
|
||||
// if ($flash) {
|
||||
// toast.error($flash.message, {
|
||||
// duration: 5000
|
||||
// });
|
||||
// }
|
||||
// }
|
||||
</script>
|
||||
|
||||
<svelte:head>
|
||||
|
|
|
|||
|
|
@ -1,16 +1,12 @@
|
|||
<script lang="ts">
|
||||
import "$lib/styles/app.pcss";
|
||||
import { onMount } from "svelte";
|
||||
import { getFlash } from 'sveltekit-flash-message/client';
|
||||
// import { getFlash } from 'sveltekit-flash-message/client';
|
||||
import toast, { Toaster } from 'svelte-french-toast';
|
||||
import { navigating, page } from '$app/stores';
|
||||
import { page } from '$app/stores';
|
||||
import { MetaTags } from 'svelte-meta-tags';
|
||||
import debounce from 'just-debounce-it';
|
||||
import 'iconify-icon';
|
||||
import Analytics from '$lib/components/analytics.svelte';
|
||||
import Portal from "$lib/Portal.svelte";
|
||||
import Loading from "$components/loading.svelte";
|
||||
import { boredState } from '$lib/stores/boredState';
|
||||
import { theme } from '$state/theme';
|
||||
|
||||
const dev = process.env.NODE_ENV !== 'production';
|
||||
|
|
@ -30,27 +26,28 @@
|
|||
...$page.data.metaTagsChild
|
||||
}
|
||||
|
||||
const flash = getFlash(page, {
|
||||
clearAfterMs: 6000
|
||||
});
|
||||
let flashType;
|
||||
let flashMessage;
|
||||
$: flashType = $flash?.type;
|
||||
$: flashMessage = $flash?.message;
|
||||
// const flash = getFlash(page, {
|
||||
// clearAfterMs: 6000
|
||||
// });
|
||||
|
||||
$: {
|
||||
if ($navigating) {
|
||||
debounce(() => {
|
||||
boredState.update((n) => ({ ...n, loading: true }));
|
||||
}, 250);
|
||||
}
|
||||
if (!$navigating) {
|
||||
boredState.update((n) => ({ ...n, loading: false }));
|
||||
}
|
||||
}
|
||||
// let flashType;
|
||||
// let flashMessage;
|
||||
// $: flashType = $flash?.type;
|
||||
// $: flashMessage = $flash?.message;
|
||||
|
||||
$: isOpen = $boredState?.dialog?.isOpen;
|
||||
$: loading = $boredState?.loading;
|
||||
// $: {
|
||||
// if ($navigating) {
|
||||
// debounce(() => {
|
||||
// boredState.update((n) => ({ ...n, loading: true }));
|
||||
// }, 250);
|
||||
// }
|
||||
// if (!$navigating) {
|
||||
// boredState.update((n) => ({ ...n, loading: false }));
|
||||
// }
|
||||
// }
|
||||
|
||||
// $: isOpen = $boredState?.dialog?.isOpen;
|
||||
// $: loading = $boredState?.loading;
|
||||
|
||||
onMount(() => {
|
||||
// set the theme to the user's active theme
|
||||
|
|
@ -58,21 +55,21 @@
|
|||
document.querySelector('html')?.setAttribute('data-theme', $theme);
|
||||
});
|
||||
|
||||
flash.subscribe(($flash) => {
|
||||
if (!$flash) return;
|
||||
// flash.subscribe(($flash) => {
|
||||
// if (!$flash) return;
|
||||
|
||||
if ($flash.type == 'success') {
|
||||
toast.success($flash.message);
|
||||
} else {
|
||||
toast.error($flash.message, {
|
||||
duration: 5000
|
||||
});
|
||||
}
|
||||
// if ($flash.type == 'success') {
|
||||
// toast.success($flash.message);
|
||||
// } else {
|
||||
// toast.error($flash.message, {
|
||||
// duration: 5000
|
||||
// });
|
||||
// }
|
||||
|
||||
// Clearing the flash message could sometimes
|
||||
// be required here to avoid double-toasting.
|
||||
flash.set(undefined);
|
||||
});
|
||||
// // Clearing the flash message could sometimes
|
||||
// // be required here to avoid double-toasting.
|
||||
// flash.set(undefined);
|
||||
// });
|
||||
</script>
|
||||
|
||||
{#if !dev}
|
||||
|
|
@ -85,7 +82,7 @@
|
|||
<slot />
|
||||
</div>
|
||||
|
||||
{#if loading}
|
||||
<!-- {#if loading}
|
||||
<Portal>
|
||||
<div class="loading">
|
||||
<Loading />
|
||||
|
|
@ -93,7 +90,7 @@
|
|||
</div>
|
||||
<div class="background" />
|
||||
</Portal>
|
||||
{/if}
|
||||
{/if} -->
|
||||
|
||||
<Toaster />
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { error, json } from '@sveltejs/kit';
|
||||
import prisma from '$lib/prisma';
|
||||
|
||||
// Search a user's collection
|
||||
export async function GET({ url, locals, params }) {
|
||||
|
|
@ -17,7 +18,7 @@ export async function GET({ url, locals, params }) {
|
|||
throw error(401, { message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
let collection = await locals.prisma.collection.findUnique({
|
||||
let collection = await prisma.collection.findUnique({
|
||||
where: {
|
||||
user_id: locals.user.userId
|
||||
}
|
||||
|
|
@ -31,7 +32,7 @@ export async function GET({ url, locals, params }) {
|
|||
|
||||
try {
|
||||
const orderBy = { [sort]: order };
|
||||
let collection_items = await locals.prisma.collectionItem.findMany({
|
||||
let collection_items = await prisma.collectionItem.findMany({
|
||||
where: {
|
||||
collection_id,
|
||||
AND: [
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
import { error, json } from '@sveltejs/kit';
|
||||
import type { Prisma } from '@prisma/client';
|
||||
import kebabCase from 'just-kebab-case';
|
||||
import prisma from '$lib/prisma';
|
||||
|
||||
// Search a user's collection
|
||||
export const GET = async ({ url, locals }) => {
|
||||
|
|
@ -17,7 +17,7 @@ export const GET = async ({ url, locals }) => {
|
|||
try {
|
||||
let games = [];
|
||||
if (exact) {
|
||||
games = await locals.prisma.game.findFirst({
|
||||
games = await prisma.game.findFirst({
|
||||
where: {
|
||||
name: {
|
||||
equals: q
|
||||
|
|
@ -31,7 +31,7 @@ export const GET = async ({ url, locals }) => {
|
|||
}
|
||||
});
|
||||
} else {
|
||||
games = await locals.prisma.game.findMany({
|
||||
games = await prisma.game.findMany({
|
||||
orderBy: {
|
||||
_relevance: {
|
||||
fields: ['name'],
|
||||
|
|
|
|||
|
|
@ -1,4 +1,5 @@
|
|||
import { error, json } from '@sveltejs/kit';
|
||||
import prisma from '$lib/prisma';
|
||||
|
||||
// Search a user's collection
|
||||
export async function GET({ url, locals, params }) {
|
||||
|
|
@ -17,7 +18,7 @@ export async function GET({ url, locals, params }) {
|
|||
throw error(401, { message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
let collection = await locals.prisma.collection.findUnique({
|
||||
let collection = await prisma.collection.findUnique({
|
||||
where: {
|
||||
user_id: locals.user.userId
|
||||
}
|
||||
|
|
@ -31,7 +32,7 @@ export async function GET({ url, locals, params }) {
|
|||
|
||||
try {
|
||||
const orderBy = { [sort]: order };
|
||||
let collection_items = await locals.prisma.collectionItem.findMany({
|
||||
let collection_items = await prisma.collectionItem.findMany({
|
||||
where: {
|
||||
collection_id,
|
||||
AND: [
|
||||
|
|
|
|||
|
|
@ -26,7 +26,10 @@ const config = {
|
|||
},
|
||||
shadcn: {
|
||||
componentPath: './src/lib/components/ui'
|
||||
}
|
||||
},
|
||||
compilerOptions: {
|
||||
enableSourcemap: true,
|
||||
}
|
||||
};
|
||||
|
||||
export default config;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
import { sentrySvelteKit } from "@sentry/sveltekit";
|
||||
import { sveltekit } from '@sveltejs/kit/vite';
|
||||
import { defineConfig } from 'vite';
|
||||
import fs from 'fs';
|
||||
// import fs from 'fs';
|
||||
|
||||
export default defineConfig({
|
||||
plugins: [
|
||||
sentrySvelteKit({
|
||||
sourceMapsUploadOptions: {
|
||||
org: process.env.SENTRY_ORG,
|
||||
project: process.env.SENTRY_PROJECT,
|
||||
authToken: process.env.SENTRY_AUTH_TOKEN,
|
||||
cleanArtifacts: true,
|
||||
org: process.env.SENTRY_ORG,
|
||||
project: process.env.SENTRY_PROJECT,
|
||||
authToken: process.env.SENTRY_AUTH_TOKEN,
|
||||
cleanArtifacts: true,
|
||||
}
|
||||
}),
|
||||
sveltekit(), rawFonts(['.ttf'])
|
||||
sveltekit()
|
||||
// , rawFonts(['.ttf'])
|
||||
],
|
||||
test: {
|
||||
include: ['src/**/*.{test,spec}.{js,ts}']
|
||||
|
|
@ -43,14 +44,14 @@ export default defineConfig({
|
|||
}
|
||||
});
|
||||
|
||||
function rawFonts(ext) {
|
||||
return {
|
||||
name: 'vite-plugin-raw-fonts',
|
||||
transform(code, id) {
|
||||
if (ext.some((e) => id.endsWith(e))) {
|
||||
const buffer = fs.readFileSync(id);
|
||||
return { code: `export default ${JSON.stringify(buffer)}`, map: null };
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
// function rawFonts(ext) {
|
||||
// return {
|
||||
// name: 'vite-plugin-raw-fonts',
|
||||
// transform(code, id) {
|
||||
// if (ext.some((e) => id.endsWith(e))) {
|
||||
// const buffer = fs.readFileSync(id);
|
||||
// return { code: `export default ${JSON.stringify(buffer)}`, map: null };
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
// }
|
||||
Loading…
Reference in a new issue