feat: add bottle editing and purchase price tracking

This commit is contained in:
2025-12-18 12:16:01 +01:00
parent 6e09300bab
commit 970dabbbf6
5 changed files with 234 additions and 0 deletions

View File

@@ -0,0 +1,50 @@
'use server';
import { createServerActionClient } from '@supabase/auth-helpers-nextjs';
import { cookies } from 'next/headers';
import { revalidatePath } from 'next/cache';
export async function updateBottle(bottleId: string, data: {
name?: string;
distillery?: string;
category?: string;
abv?: number;
age?: number;
whiskybase_id?: string;
purchase_price?: number;
}) {
const supabase = createServerActionClient({ cookies });
try {
const { data: { session } } = await supabase.auth.getSession();
if (!session) throw new Error('Nicht autorisiert');
const { error } = await supabase
.from('bottles')
.update({
name: data.name,
distillery: data.distillery,
category: data.category,
abv: data.abv,
age: data.age,
whiskybase_id: data.whiskybase_id,
purchase_price: data.purchase_price,
updated_at: new Date().toISOString(),
})
.eq('id', bottleId)
.eq('user_id', session.user.id);
if (error) throw error;
revalidatePath(`/bottles/${bottleId}`);
revalidatePath('/');
return { success: true };
} catch (error) {
console.error('Update Bottle Error:', error);
return {
success: false,
error: error instanceof Error ? error.message : 'Fehler beim Aktualisieren der Flaschendaten',
};
}
}