diff options
Diffstat (limited to 'src/routes')
| -rw-r--r-- | src/routes/+page.server.ts | 7 | ||||
| -rw-r--r-- | src/routes/groceries/+page.server.ts | 6 | ||||
| -rw-r--r-- | src/routes/groceries/catalog/+page.server.ts | 9 | ||||
| -rw-r--r-- | src/routes/grocery/[id]/+page.server.ts | 34 | ||||
| -rw-r--r-- | src/routes/projects/[id]/+page.server.ts | 23 | ||||
| -rw-r--r-- | src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts | 9 |
6 files changed, 43 insertions, 45 deletions
diff --git a/src/routes/+page.server.ts b/src/routes/+page.server.ts index 008f7f3..ac00aeb 100644 --- a/src/routes/+page.server.ts +++ b/src/routes/+page.server.ts @@ -1,12 +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 = { @@ -16,7 +15,7 @@ export const actions: Actions = { return fail(400, { error: 'Le nom est requis' }); } try { - await addProject(name); + await projectsService.add(name); } catch (error) { if (isUniqueViolation(error)) { return fail(400, { error: 'Ce projet existe déjà' }); diff --git a/src/routes/groceries/+page.server.ts b/src/routes/groceries/+page.server.ts index 1cae275..d33c6a5 100644 --- a/src/routes/groceries/+page.server.ts +++ b/src/routes/groceries/+page.server.ts @@ -1,4 +1,4 @@ -import { loadUnchecked, loadAll } from '$lib/server/services/groceries'; +import { groceriesService } from '$lib/server/services'; import { addGroceryAction, addGroceryAndEditAction, @@ -15,8 +15,8 @@ export interface GroceriesOutput { } export const load: PageServerLoad = async () => { - const unchecked = await loadUnchecked(); - const all = await loadAll(); + const unchecked = await groceriesService.loadUnchecked(); + const all = await groceriesService.loadAll(); return { items: unchecked.items, categories: unchecked.categories, diff --git a/src/routes/groceries/catalog/+page.server.ts b/src/routes/groceries/catalog/+page.server.ts index fd71e30..8d94154 100644 --- a/src/routes/groceries/catalog/+page.server.ts +++ b/src/routes/groceries/catalog/+page.server.ts @@ -1,8 +1,5 @@ import { fail } from '@sveltejs/kit'; -import { - loadAll, - bulkUpdateGroceryCategory, -} from '$lib/server/services/groceries'; +import { groceriesService } from '$lib/server/services'; import { toggleGroceryAction } from '$lib/server/services/grocery-actions'; import { numericId, @@ -18,7 +15,7 @@ export interface CatalogOutput { } export const load: PageServerLoad = async () => { - return loadAll(); + return groceriesService.loadAll(); }; export const actions: Actions = { @@ -34,7 +31,7 @@ export const actions: Actions = { return fail(400, { error: 'Aucun article sélectionné' }); } - await bulkUpdateGroceryCategory(ids, categoryId); + await groceriesService.bulkUpdateGroceryCategory(ids, categoryId); return { success: true, type: 'bulkUpdate' as const }; }, }; diff --git a/src/routes/grocery/[id]/+page.server.ts b/src/routes/grocery/[id]/+page.server.ts index 0f386f3..dbfecff 100644 --- a/src/routes/grocery/[id]/+page.server.ts +++ b/src/routes/grocery/[id]/+page.server.ts @@ -2,14 +2,11 @@ import { error, fail, redirect } from '@sveltejs/kit'; import { db } from '$lib/server/db'; import { groceries, categories } from '$lib/server/db/schema'; import { eq } from 'drizzle-orm'; -import { categoriesService } from '$lib/server/services'; import { - loadForGrocery, - add as addRef, - promote, - deleteReference, -} from '$lib/server/services/references'; -import { updateGrocery, deleteGrocery } from '$lib/server/services/groceries'; + categoriesService, + groceriesService, + referencesService, +} from '$lib/server/services'; import { idAction } from '$lib/server/services/grocery-actions'; import { numericId, @@ -39,7 +36,7 @@ export const load: PageServerLoad = async ({ params, url }) => { .where(eq(categories.id, item.categoryId)) : [null]; - const refs = await loadForGrocery(id); + const refs = await referencesService.loadForGrocery(id); const cats = await categoriesService.loadAll(); const from = url.searchParams.get('from') || '/'; @@ -67,14 +64,25 @@ export const actions: Actions = { return fail(400, { error: 'La référence est requise' }); } - await addRef(groceryId, reference, price, unit, qualityScore); + await referencesService.add( + groceryId, + reference, + price, + unit, + qualityScore, + ); return { success: true, type: 'add' as const }; }, delete: ({ request }) => - idAction(request, deleteReference, { type: 'delete' }), + idAction(request, (id) => referencesService.deleteReference(id), { + type: 'delete', + }), - promote: ({ request }) => idAction(request, promote, { type: 'promote' }), + promote: ({ request }) => + idAction(request, (id) => referencesService.promote(id), { + type: 'promote', + }), update: async ({ request, params }) => { const data = await request.formData(); @@ -88,7 +96,7 @@ export const actions: Actions = { } try { - await updateGrocery(groceryId, name, categoryId); + await groceriesService.updateGrocery(groceryId, name, categoryId); } catch (error) { if (isUniqueViolation(error)) { return fail(400, { error: 'Un article porte déjà ce nom' }); @@ -100,7 +108,7 @@ export const actions: Actions = { deleteItem: async ({ params, request }) => { const groceryId = numericId(params.id); - await deleteGrocery(groceryId); + await groceriesService.deleteGrocery(groceryId); const data = await request.formData(); const from = parseFormString(data.get('from')) || '/'; throw redirect(303, from); diff --git a/src/routes/projects/[id]/+page.server.ts b/src/routes/projects/[id]/+page.server.ts index 83d7571..1df28c2 100644 --- a/src/routes/projects/[id]/+page.server.ts +++ b/src/routes/projects/[id]/+page.server.ts @@ -1,13 +1,5 @@ import { error, fail, redirect } from '@sveltejs/kit'; -import { - archive as archiveProject, - getById, -} from '$lib/server/services/projects'; -import { - add, - loadProjectDashboard, - loadArchived, -} from '$lib/server/services/routines'; +import { projectsService, routinesService } from '$lib/server/services'; import { completeRoutineAction } from '$lib/server/services/routine-actions'; import { numericId, parseFormString } from '$lib/server/services/validation'; import { Frequency } from '$lib/shared/frequency'; @@ -15,12 +7,15 @@ import type { Actions, PageServerLoad } from './$types'; export const load: PageServerLoad = async ({ params }) => { const id = numericId(params.id); - const project = await getById(id); + const project = await projectsService.getById(id); if (!project || project.archived) { throw error(404, 'Projet introuvable'); } - const dashboard = await loadProjectDashboard(id, Temporal.Now.instant()); - const archived = await loadArchived(id); + const dashboard = await routinesService.loadProjectDashboard( + id, + Temporal.Now.instant(), + ); + const archived = await routinesService.loadArchived(id); return { project: { id: project.id, name: project.name }, routines: dashboard.routines, @@ -38,7 +33,7 @@ export const actions: Actions = { return fail(400, { error: 'Le nom est requis' }); } try { - await add( + await routinesService.add( numericId(params.id), name, Frequency.parse(data.get('frequency')?.toString() ?? '').toSpec(), @@ -55,7 +50,7 @@ export const actions: Actions = { }, archiveProject: async ({ params }) => { - await archiveProject(numericId(params.id)); + await projectsService.archive(numericId(params.id)); throw redirect(303, '/'); }, }; diff --git a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts index cb14e0d..4ace86f 100644 --- a/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts +++ b/src/routes/projects/[projectId]/routine/[routineId]/+page.server.ts @@ -1,6 +1,5 @@ import { error } from '@sveltejs/kit'; -import { getById } from '$lib/server/services/projects'; -import { loadCurrent, loadCompletions } from '$lib/server/services/routines'; +import { projectsService, routinesService } from '$lib/server/services'; import { archiveRoutineAction, completeRoutineAction, @@ -14,17 +13,17 @@ export const load: PageServerLoad = async ({ params }) => { const projectId = numericId(params.projectId); const routineId = numericId(params.routineId); - const project = await getById(projectId); + const project = await projectsService.getById(projectId); if (!project || project.archived) { throw error(404, 'Projet introuvable'); } - const routine = await loadCurrent(routineId); + const routine = await routinesService.loadCurrent(routineId); if (!routine || routine.projectId !== projectId) { throw error(404, 'Routine introuvable'); } - const completions = await loadCompletions(routineId); + const completions = await routinesService.loadCompletions(routineId); // Archived routines are frozen at their archive instant, not now. const at = routine.archivedAt ? Temporal.Instant.from(routine.archivedAt) |
