aboutsummaryrefslogtreecommitdiff
path: root/src/routes/catalog/+page.server.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/routes/catalog/+page.server.ts')
-rw-r--r--src/routes/catalog/+page.server.ts25
1 files changed, 23 insertions, 2 deletions
diff --git a/src/routes/catalog/+page.server.ts b/src/routes/catalog/+page.server.ts
index 69a775a..22464dc 100644
--- a/src/routes/catalog/+page.server.ts
+++ b/src/routes/catalog/+page.server.ts
@@ -1,6 +1,13 @@
import { fail } from '@sveltejs/kit';
-import { loadAll, toggle } from '$lib/server/services/groceries';
-import { numericId } from '$lib/server/services/validation';
+import {
+ loadAll,
+ toggle,
+ bulkUpdateGroceryCategory,
+} from '$lib/server/services/groceries';
+import {
+ numericId,
+ parseOptionalNumber,
+} from '$lib/server/services/validation';
import type { EnrichedGrocery } from '$lib/server/services/groceries';
import type { Category } from '$lib/server/services/types';
import type { Actions, PageServerLoad } from './$types';
@@ -25,4 +32,18 @@ export const actions: Actions = {
}
return { success: true };
},
+
+ bulkUpdateCategory: async ({ request }) => {
+ const data = await request.formData();
+ const ids = data.getAll('ids').map(numericId);
+ const rawCategoryId = parseOptionalNumber(data.get('category_id'));
+ const categoryId = rawCategoryId === -1 ? null : rawCategoryId;
+
+ if (ids.length === 0) {
+ return fail(400, { error: 'Aucun article sélectionné' });
+ }
+
+ await bulkUpdateGroceryCategory(ids, categoryId);
+ return { success: true, type: 'bulkUpdate' as const };
+ },
};