aboutsummaryrefslogtreecommitdiff
path: root/src/lib/server/services/grocery-actions.ts
blob: 0966c921d777c3e4aa796a95ed78bd9c25fb4eff (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14

import { fail } from '@sveltejs/kit';
import { toggle } from './groceries';
import { numericId } from './validation';

export async function toggleGroceryAction(request: 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 };
}