diff options
Diffstat (limited to 'src/routes/catalog/+page.server.ts')
| -rw-r--r-- | src/routes/catalog/+page.server.ts | 49 |
1 files changed, 0 insertions, 49 deletions
diff --git a/src/routes/catalog/+page.server.ts b/src/routes/catalog/+page.server.ts deleted file mode 100644 index 22464dc..0000000 --- a/src/routes/catalog/+page.server.ts +++ /dev/null @@ -1,49 +0,0 @@ -import { fail } from '@sveltejs/kit'; -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'; - -export interface CatalogOutput { - items: EnrichedGrocery[]; - categories: Category[]; -} - -export const load: PageServerLoad = async () => { - return loadAll(); -}; - -export const actions: Actions = { - toggle: async ({ request }) => { - const data = await request.formData(); - try { - const id = numericId(data.get('id')); - await toggle(id); - } catch { - return fail(400, { error: 'ID invalide' }); - } - 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 }; - }, -}; |
