Some checks failed
Test and deploy staging / staging (push) Has been cancelled
37 lines
1.1 KiB
TypeScript
Executable File
37 lines
1.1 KiB
TypeScript
Executable File
import { fail } from '@sveltejs/kit';
|
|
import { db } from '$lib/server/db';
|
|
import { listItemCompletions } from '$lib/server/db/schema';
|
|
import { eq } from 'drizzle-orm';
|
|
import type { PageServerLoad } from './$types';
|
|
|
|
export const load: PageServerLoad = async ({ locals }) => {
|
|
const lists = await db.query.lists.findMany({
|
|
columns: { id: true, name: true, slug: true, isProgress: true },
|
|
with: { items: { columns: { id: true } } },
|
|
orderBy: { id: 'desc' }
|
|
});
|
|
|
|
const completed = new Set(
|
|
locals.user
|
|
? (
|
|
await db
|
|
.select({ itemId: listItemCompletions.itemId })
|
|
.from(listItemCompletions)
|
|
.where(eq(listItemCompletions.userId, locals.user.id))
|
|
).map((row) => row.itemId)
|
|
: []
|
|
);
|
|
return {
|
|
lists: lists.map(({ items, ...list }) => ({
|
|
...list,
|
|
total: items.length,
|
|
checked: list.isProgress ? items.filter((item) => completed.has(item.id)).length : 0
|
|
}))
|
|
};
|
|
};
|
|
|
|
// Retire the old shared-token login; legacy cookies grant no permissions.
|
|
export const actions = {
|
|
authenticate: () => fail(410, { message: 'Use the central account login at /login' })
|
|
};
|