diff options
Diffstat (limited to 'src/routes/+page.server.ts')
| -rw-r--r-- | src/routes/+page.server.ts | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index fe9b4e3..ac00aeb 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,11 +1,11 @@ import { fail } from '@sveltejs/kit'; -import { loadOverview } from '$lib/server/services/routines'; -import { add as addProject } from '$lib/server/services/projects'; +import { projectsService, routinesService } from '$lib/server/services'; 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()); + return routinesService.loadOverview(Temporal.Now.instant()); }; export const actions: Actions = { @@ -14,7 +14,14 @@ export const actions: Actions = { if (!name) { return fail(400, { error: 'Le nom est requis' }); } - await addProject(name); + try { + await projectsService.add(name); + } catch (error) { + if (isUniqueViolation(error)) { + return fail(400, { error: 'Ce projet existe déjà' }); + } + throw error; + } return { success: true }; }, }; |
