mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
35 lines
610 B
TypeScript
35 lines
610 B
TypeScript
import prisma from '$lib/prisma.js';
|
|
import { redirect } from '@sveltejs/kit';
|
|
|
|
export async function load({ params, locals }) {
|
|
const session = await locals.auth.validate();
|
|
if (!session) {
|
|
throw redirect(302, '/login');
|
|
}
|
|
|
|
try {
|
|
let wishlists = await prisma.wishlist.findMany({
|
|
where: {
|
|
user_id: session.userId
|
|
}
|
|
});
|
|
|
|
if (wishlists.length === 0) {
|
|
const wishlist = await prisma.wishlist.create({
|
|
data: {
|
|
user_id: session.userId
|
|
}
|
|
});
|
|
wishlists.push(wishlist);
|
|
}
|
|
|
|
return {
|
|
wishlists
|
|
};
|
|
} catch (e) {
|
|
console.error(e);
|
|
}
|
|
return {
|
|
wishlists: []
|
|
};
|
|
}
|