diff options
| author | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-07-29 10:31:36 +0200 |
|---|---|---|
| committer | Martin Kagamino Lehoux <martin@lehoux.net> | 2026-07-29 10:31:36 +0200 |
| commit | 684d3c954e3577a6488101bf5ee85e36439fd53c (patch) | |
| tree | e9404b8eea57e811faaa9821675376f309d649e9 /src/routes/catalog/+page.server.ts | |
| parent | 94212274cecf4da5f94b246a7ac9ab87077fb77f (diff) | |
feat: multi-select and bulk-update category from catalog
Diffstat (limited to 'src/routes/catalog/+page.server.ts')
| -rw-r--r-- | src/routes/catalog/+page.server.ts | 25 |
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 }; + }, }; |
