import { fail } from '@sveltejs/kit'; import { loadAll, toggle } from '$lib/server/services/groceries'; import { numericId } from '$lib/server/services/validation'; import type { EnrichedGrocery } from '$lib/server/services/groceries'; import type { Category } from '$lib/server/services/types'; import type { Actions, PageServerLoad } from './$types'; export interface CatalogOutput { items: EnrichedGrocery[]; categories: Category[]; } export const load: PageServerLoad = async () => { return loadAll(); }; export const actions: Actions = { toggle: async ({ request }) => { const data = await request.formData(); try { const id = numericId(data.get('id')); await toggle(id); } catch { return fail(400, { error: 'ID invalide' }); } return { success: true }; }, };