feat: PantryItem (Baslager) - tabell, backend-modul och frontend-sida
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
'use server';
|
||||
|
||||
import { revalidatePath } from 'next/cache';
|
||||
import { API_BASE } from '../../lib/api';
|
||||
|
||||
export async function addPantryItem(productId: number) {
|
||||
const res = await fetch(`${API_BASE}/api/pantry`, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ productId }),
|
||||
cache: 'no-store',
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(`Kunde inte lägga till i baslagret: ${text}`);
|
||||
}
|
||||
|
||||
revalidatePath('/baslager');
|
||||
}
|
||||
|
||||
export async function removePantryItem(id: number) {
|
||||
const res = await fetch(`${API_BASE}/api/pantry/${id}`, {
|
||||
method: 'DELETE',
|
||||
cache: 'no-store',
|
||||
});
|
||||
|
||||
if (!res.ok) {
|
||||
const text = await res.text();
|
||||
throw new Error(`Kunde inte ta bort från baslagret: ${text}`);
|
||||
}
|
||||
|
||||
revalidatePath('/baslager');
|
||||
}
|
||||
Reference in New Issue
Block a user