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/routes/groceries | |
| 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/routes/groceries')
| -rw-r--r-- | src/routes/groceries/categories/+page.server.ts | 13 |
1 files changed, 5 insertions, 8 deletions
diff --git a/src/routes/groceries/categories/+page.server.ts b/src/routes/groceries/categories/+page.server.ts index 6e0e3b7..e8794fa 100644 --- a/src/routes/groceries/categories/+page.server.ts +++ b/src/routes/groceries/categories/+page.server.ts @@ -1,9 +1,5 @@ import { fail } from '@sveltejs/kit'; -import { - loadAll, - deleteCategory, - reorder, -} from '$lib/server/services/categories'; +import { categoriesService } from '$lib/server/services'; import { addCategoryAction, idAction, @@ -17,13 +13,14 @@ export interface CategoriesOutput { } export const load: PageServerLoad = async () => { - return { categories: await loadAll() }; + return { categories: await categoriesService.loadAll() }; }; export const actions: Actions = { add: ({ request }) => addCategoryAction(request), - delete: ({ request }) => idAction(request, deleteCategory), + delete: ({ request }) => + idAction(request, (id) => categoriesService.deleteCategory(id)), reorder: async ({ request }) => { const data = await request.formData(); @@ -31,7 +28,7 @@ export const actions: Actions = { if (ids.length === 0) { return fail(400, { error: 'Aucune catégorie' }); } - await reorder(ids); + await categoriesService.reorder(ids); return { success: true }; }, }; |
