mirror of
https://github.com/BradNut/boredgame
synced 2025-09-08 17:40:22 +00:00
Removing hopefully that last of prisma, convert the files to use drizzle, and fix shadcn-svelte pagination with newer lucide icon.
This commit is contained in:
parent
a267cb5193
commit
e7d1df356e
10 changed files with 49 additions and 74 deletions
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { Button as ButtonPrimitive } from "bits-ui";
|
||||
import { cn } from "$lib/utils";
|
||||
import { buttonVariants, type Props, type Events } from ".";
|
||||
import { cn } from "$lib/utils.js";
|
||||
import { buttonVariants, type Props, type Events } from "./index.js";
|
||||
|
||||
type $$Props = Props;
|
||||
type $$Events = Events;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { cn } from "$lib/utils";
|
||||
import { cn } from "$lib/utils.js";
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLUListElement>;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<script lang="ts">
|
||||
import MoreHorizontal from "lucide-svelte/icons/more-horizontal";
|
||||
import { cn } from "$lib/utils";
|
||||
import Ellipsis from "lucide-svelte/icons/ellipsis";
|
||||
import { cn } from "$lib/utils.js";
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLSpanElement>;
|
||||
|
|
@ -14,6 +14,6 @@
|
|||
class={cn("flex h-9 w-9 items-center justify-center", className)}
|
||||
{...$$restProps}
|
||||
>
|
||||
<MoreHorizontal class="h-4 w-4" />
|
||||
<Ellipsis class="h-4 w-4" />
|
||||
<span class="sr-only">More pages</span>
|
||||
</span>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<script lang="ts">
|
||||
import { cn } from "$lib/utils";
|
||||
import { cn } from "$lib/utils.js";
|
||||
import type { HTMLAttributes } from "svelte/elements";
|
||||
|
||||
type $$Props = HTMLAttributes<HTMLLIElement>;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { Pagination as PaginationPrimitive } from "bits-ui";
|
||||
import { cn } from "$lib/utils";
|
||||
import { buttonVariants, type Props } from "$lib/components/ui/button";
|
||||
import { cn } from "$lib/utils.js";
|
||||
import { buttonVariants, type Props } from "$lib/components/ui/button/index.js";
|
||||
|
||||
type $$Props = PaginationPrimitive.PageProps &
|
||||
Props & {
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script lang="ts">
|
||||
import { Pagination as PaginationPrimitive } from "bits-ui";
|
||||
import ChevronRight from "lucide-svelte/icons/chevron-right";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { cn } from "$lib/utils";
|
||||
import { Button } from "$lib/components/ui/button/index.js";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = PaginationPrimitive.NextButtonProps;
|
||||
type $$Events = PaginationPrimitive.NextButtonEvents;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<script lang="ts">
|
||||
import { Pagination as PaginationPrimitive } from "bits-ui";
|
||||
import ChevronLeft from "lucide-svelte/icons/chevron-left";
|
||||
import { Button } from "$lib/components/ui/button";
|
||||
import { cn } from "$lib/utils";
|
||||
import { Button } from "$lib/components/ui/button/index.js";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = PaginationPrimitive.PrevButtonProps;
|
||||
type $$Events = PaginationPrimitive.PrevButtonEvents;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
<script lang="ts">
|
||||
import { Pagination as PaginationPrimitive } from "bits-ui";
|
||||
|
||||
import { cn } from "$lib/utils";
|
||||
import { cn } from "$lib/utils.js";
|
||||
|
||||
type $$Props = PaginationPrimitive.Props;
|
||||
type $$Events = PaginationPrimitive.Events;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import { error, json } from '@sveltejs/kit';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import db from '$lib/drizzle.js';
|
||||
import { collection_items, collection_items, users } from '../../../../../schema.js';
|
||||
import { collection_items, users } from '../../../../../schema.js';
|
||||
|
||||
// Search a user's collection
|
||||
export async function GET({ url, locals, params }) {
|
||||
|
|
@ -12,16 +12,15 @@ export async function GET({ url, locals, params }) {
|
|||
const order = searchParams?.order || 'asc';
|
||||
const sort = searchParams?.sort || 'name';
|
||||
const collection_id = params.id;
|
||||
const session = await locals.auth.validate();
|
||||
console.log('url', url);
|
||||
console.log('username', locals?.user?.id);
|
||||
|
||||
if (!session) {
|
||||
if (!locals.user) {
|
||||
error(401, { message: 'Unauthorized' });
|
||||
}
|
||||
|
||||
const collection = await db.query.collections.findFirst({
|
||||
where: eq(users.id, locals?.user?.userId)
|
||||
where: eq(users.id, locals?.user?.id)
|
||||
});
|
||||
console.log('collection', collection);
|
||||
|
||||
|
|
@ -31,40 +30,30 @@ export async function GET({ url, locals, params }) {
|
|||
}
|
||||
|
||||
try {
|
||||
const orderBy = { [sort]: order };
|
||||
let collection_items = await db.query.collection_items.findMany({
|
||||
const userCollectionItems = await db.query.collection_items.findMany({
|
||||
where: eq(collection_items.collection_id, collection_id),
|
||||
AND: [
|
||||
{
|
||||
game: {
|
||||
name: {
|
||||
contains: q
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
},
|
||||
orderBy: [
|
||||
{
|
||||
game: {
|
||||
...orderBy
|
||||
}
|
||||
}
|
||||
],
|
||||
include: {
|
||||
with: {
|
||||
game: {
|
||||
select: {
|
||||
columns: {
|
||||
id: true,
|
||||
name: true,
|
||||
thumb_url: true
|
||||
}
|
||||
},
|
||||
}
|
||||
},
|
||||
skip,
|
||||
take: limit
|
||||
orderBy: (collection_items, { asc, desc }) => {
|
||||
const dbSort = sort === 'dateAdded' ? collection_items.created_at : collection_items.times_played;
|
||||
if (order === 'asc') {
|
||||
return asc(dbSort);
|
||||
} else {
|
||||
return desc(dbSort);
|
||||
}
|
||||
},
|
||||
offset: skip,
|
||||
limit
|
||||
});
|
||||
|
||||
return json(collection_items);
|
||||
return json(userCollectionItems);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
error(500, { message: 'Something went wrong' });
|
||||
|
|
|
|||
|
|
@ -1,18 +1,16 @@
|
|||
import { error, json } from '@sveltejs/kit';
|
||||
import prisma from '$lib/prisma';
|
||||
import { and, eq } from 'drizzle-orm';
|
||||
import { collection_items } from '../../../../../schema.js';
|
||||
import { eq } from 'drizzle-orm';
|
||||
import db from '$lib/drizzle.js';
|
||||
import { wishlist_items, wishlists } from '../../../../../schema.js';
|
||||
|
||||
// Search a user's collection
|
||||
export async function GET({ url, locals, params }) {
|
||||
const searchParams = Object.fromEntries(url.searchParams);
|
||||
const q = searchParams?.q || '';
|
||||
// const q = searchParams?.q || '';
|
||||
const limit = parseInt(searchParams?.limit) || 10;
|
||||
const skip = parseInt(searchParams?.skip) || 0;
|
||||
const order = searchParams?.order || 'asc';
|
||||
const sort = searchParams?.sort || 'name';
|
||||
const collection_id = params.id;
|
||||
const wishlist_id = params.id;
|
||||
console.log('url', url);
|
||||
console.log('username', locals?.user?.id);
|
||||
|
||||
|
|
@ -22,32 +20,30 @@ export async function GET({ url, locals, params }) {
|
|||
});
|
||||
}
|
||||
|
||||
const collection = await db.collection.findUnique({
|
||||
where: {
|
||||
user_id: locals.user.id
|
||||
}
|
||||
const wishlist = await db.query.wishlists.findFirst({
|
||||
where: eq(wishlists.user_id, locals?.user?.id)
|
||||
});
|
||||
console.log('collection', collection);
|
||||
console.log('wishlist', wishlist);
|
||||
|
||||
if (!collection) {
|
||||
console.log('Collection was not found');
|
||||
error(404, { message: 'Collection was not found' });
|
||||
if (!wishlist) {
|
||||
console.log('Wishlist was not found');
|
||||
error(404, { message: 'Wishlist was not found' });
|
||||
}
|
||||
|
||||
try {
|
||||
const itemsInCollection = await db.query.collection_items.findMany({
|
||||
where: eq(collection_items.collection_id, collection_id),
|
||||
const itemsInWishlist = await db.query.wishlist_items.findMany({
|
||||
where: eq(wishlist_items.wishlist_id, wishlist_id),
|
||||
with: {
|
||||
game: {
|
||||
columns: {
|
||||
id: true,
|
||||
name: true,
|
||||
thumb_url: true,
|
||||
},
|
||||
thumb_url: true
|
||||
}
|
||||
}
|
||||
},
|
||||
orderBy: (collection_items, { asc, desc }) => {
|
||||
const dbSort = sort === 'dateAdded' ? collection_items.created_at : collection_items.times_played;
|
||||
orderBy: (wishlist_items, { asc, desc }) => {
|
||||
const dbSort = wishlist_items.created_at;
|
||||
if (order === 'asc') {
|
||||
return asc(dbSort);
|
||||
} else {
|
||||
|
|
@ -58,17 +54,7 @@ export async function GET({ url, locals, params }) {
|
|||
limit
|
||||
});
|
||||
|
||||
// include: {
|
||||
// game: {
|
||||
// select: {
|
||||
// id: true,
|
||||
// name: true,
|
||||
// thumb_url: true
|
||||
// }
|
||||
// }
|
||||
// },
|
||||
|
||||
return json(collection_items);
|
||||
return json(itemsInWishlist);
|
||||
} catch (e) {
|
||||
console.error(e);
|
||||
error(500, { message: 'Something went wrong' });
|
||||
|
|
|
|||
Loading…
Reference in a new issue