import { fail } from '@sveltejs/kit'; import { loadOverview } from '$lib/server/services/routines'; import { add as addProject } from '$lib/server/services/projects'; import { parseFormString } from '$lib/server/services/validation'; import { isUniqueViolation } from '$lib/server/db/errors'; import type { Actions, PageServerLoad } from './$types'; export const load: PageServerLoad = async () => { return loadOverview(Temporal.Now.instant()); }; export const actions: Actions = { addProject: async ({ request }) => { const name = parseFormString((await request.formData()).get('name')); if (!name) { return fail(400, { error: 'Le nom est requis' }); } try { await addProject(name); } catch (error) { if (isUniqueViolation(error)) { return fail(400, { error: 'Ce projet existe déjà' }); } throw error; } return { success: true }; }, };