import { error } from '@sveltejs/kit'; import type { PageServerLoad } from './$types.js'; import { withTenant } from '$lib/server/rls.js'; import { requireBoardView } from '$lib/server/guards.js'; import { canEditBoard } from '$lib/server/permissions.js'; export const load: PageServerLoad = async ({ params, locals }) => { const tenant = locals.tenant; if (!tenant) throw error(400, 'Unknown tenant'); const board = await withTenant(tenant.id, async (tx) => { return requireBoardView(tx, locals.user, params.boardId, tenant.id); }); // Filter to cards with due dates const cardsWithDue = board.columns.flatMap((col: any) => col.cards .filter((c: any) => c.dueDate) .map((c: any) => ({ ...c, columnTitle: col.title, columnId: col.id })) ); return { board: { id: board.id, title: board.title, cardPrefix: (board as any).cardPrefix }, cards: cardsWithDue, canEdit: canEditBoard(locals.user, board.members) }; };