blob: 008f7f3142778d2db220674a9c399c1b5ba9fae8 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
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 };
},
};
|