aboutsummaryrefslogtreecommitdiff
path: root/src/routes/groceries
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-10-18 22:22:55 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-10-18 22:22:55 +0200
commit4efed80a2f8dc238b420eadf97d56c3eccaadb76 (patch)
tree7732a80745622c097a9e75dfb056603bceb10a23 /src/routes/groceries
parent0685e9ece66fbcb09c9457027cf7bb2107cc0171 (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/routes/groceries')
-rw-r--r--src/routes/groceries/+page.server.ts6
-rw-r--r--src/routes/groceries/catalog/+page.server.ts9
2 files changed, 6 insertions, 9 deletions
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 };
},
};