From 4efed80a2f8dc238b420eadf97d56c3eccaadb76 Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Sun, 18 Oct 2026 22:22:55 +0200 Subject: refactor: inject the database into every service Groceries, projects, references and routines become classes holding the Drizzle handle, wired once in services/index.ts alongside categories. Tests build their own instance on an in-memory database. Drops the unused projects.loadAll and projects.rename. --- src/lib/server/services/routine-actions.ts | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'src/lib/server/services/routine-actions.ts') diff --git a/src/lib/server/services/routine-actions.ts b/src/lib/server/services/routine-actions.ts index 1d7f8b5..ea4e91e 100644 --- a/src/lib/server/services/routine-actions.ts +++ b/src/lib/server/services/routine-actions.ts @@ -1,5 +1,5 @@ import { fail, type ActionFailure } from '@sveltejs/kit'; -import { archive, complete, edit, loadCurrent } from './routines'; +import { routinesService } from '$lib/server/services'; import { parseFormString } from './validation'; import { instantFromDay } from '$lib/shared/temporal'; import { Frequency } from '$lib/shared/frequency'; @@ -14,7 +14,7 @@ export async function editRoutineAction( routineId: number, extra?: { type: 'edit' }, ): Promise { - const current = await loadCurrent(routineId); + const current = await routinesService.loadCurrent(routineId); if (!current) { return fail(400, { error: 'Routine introuvable' }); } @@ -47,7 +47,7 @@ export async function editRoutineAction( } try { - await edit(routineId, fields); + await routinesService.edit(routineId, fields); } catch { return fail(400, { error: 'Routine introuvable' }); } @@ -55,7 +55,7 @@ export async function editRoutineAction( } export async function completeRoutineAction(data: FormData, routineId: number) { - const current = await loadCurrent(routineId); + const current = await routinesService.loadCurrent(routineId); if (!current) { return fail(400, { error: 'Routine introuvable' }); } @@ -73,7 +73,11 @@ export async function completeRoutineAction(data: FormData, routineId: number) { } try { - await complete(routineId, parseFormString(data.get('note')), doneAt); + await routinesService.complete( + routineId, + parseFormString(data.get('note')), + doneAt, + ); } catch { return fail(400, { error: 'Routine introuvable' }); } @@ -82,7 +86,7 @@ export async function completeRoutineAction(data: FormData, routineId: number) { export async function archiveRoutineAction(routineId: number) { try { - await archive(routineId); + await routinesService.archive(routineId); } catch { return fail(400, { error: 'Routine introuvable' }); } -- cgit v1.3