From 684d3c954e3577a6488101bf5ee85e36439fd53c Mon Sep 17 00:00:00 2001 From: Martin Kagamino Lehoux Date: Wed, 29 Jul 2026 10:31:36 +0200 Subject: feat: multi-select and bulk-update category from catalog --- src/routes/catalog/+page.server.ts | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'src/routes/catalog/+page.server.ts') 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 }; + }, }; -- cgit v1.3