diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-10-18 22:22:55 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-10-18 22:22:55 +0200 |
| commit | 4efed80a2f8dc238b420eadf97d56c3eccaadb76 (patch) | |
| tree | 7732a80745622c097a9e75dfb056603bceb10a23 /src/lib/server/services/routine-actions.ts | |
| parent | 0685e9ece66fbcb09c9457027cf7bb2107cc0171 (diff) | |
refactor: inject the database into every servicemain
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.
Diffstat (limited to 'src/lib/server/services/routine-actions.ts')
| -rw-r--r-- | src/lib/server/services/routine-actions.ts | 16 |
1 files changed, 10 insertions, 6 deletions
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<EditRoutineResult> { - 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' }); } |
