diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-10-18 22:02:02 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-10-18 22:02:02 +0200 |
| commit | 0685e9ece66fbcb09c9457027cf7bb2107cc0171 (patch) | |
| tree | f6dabadf2dcf55f2847a48ada2e03e491f017dcc /src/lib/server/services/grocery-actions.ts | |
| parent | c3c61894d2b119ae424bac605d4b3099e0b674e5 (diff) | |
refactor: inject the database into services via a constructor
Pilot on the categories service: a CategoriesService class holds the Drizzle
handle, and services/index.ts wires the real instance once for the server while
tests build their own on an in-memory database. AppDatabase moves from
groceries.ts to db/types.ts.
Diffstat (limited to 'src/lib/server/services/grocery-actions.ts')
| -rw-r--r-- | src/lib/server/services/grocery-actions.ts | 4 |
1 files changed, 2 insertions, 2 deletions
diff --git a/src/lib/server/services/grocery-actions.ts b/src/lib/server/services/grocery-actions.ts index cedb46e..2eff205 100644 --- a/src/lib/server/services/grocery-actions.ts +++ b/src/lib/server/services/grocery-actions.ts @@ -1,6 +1,6 @@ import { fail, redirect, type ActionFailure } from '@sveltejs/kit'; import { addOrUncheck, loadUnchecked, toggle } from './groceries'; -import { add as addCategory } from './categories'; +import { categoriesService } from '$lib/server/services'; import { numericId, parseFormString, parseOptionalNumber } from './validation'; import { isUniqueViolation } from '$lib/server/db/errors'; @@ -52,7 +52,7 @@ export async function addCategoryAction(request: Request) { } try { - await addCategory(name); + await categoriesService.add(name); } catch (error) { if (isUniqueViolation(error)) { return fail(400, { error: 'Cette catégorie existe déjà' }); |
