feat: implement buddies and tasting sessions features
This commit is contained in:
@@ -6,11 +6,13 @@ import { revalidatePath } from 'next/cache';
|
||||
|
||||
export async function saveTasting(data: {
|
||||
bottle_id: string;
|
||||
session_id?: string;
|
||||
rating: number;
|
||||
nose_notes?: string;
|
||||
palate_notes?: string;
|
||||
finish_notes?: string;
|
||||
is_sample?: boolean;
|
||||
buddy_ids?: string[];
|
||||
}) {
|
||||
const supabase = createServerActionClient({ cookies });
|
||||
|
||||
@@ -23,6 +25,7 @@ export async function saveTasting(data: {
|
||||
.insert({
|
||||
bottle_id: data.bottle_id,
|
||||
user_id: session.user.id,
|
||||
session_id: data.session_id,
|
||||
rating: data.rating,
|
||||
nose_notes: data.nose_notes,
|
||||
palate_notes: data.palate_notes,
|
||||
@@ -34,6 +37,23 @@ export async function saveTasting(data: {
|
||||
|
||||
if (error) throw error;
|
||||
|
||||
// Add buddy tags if any
|
||||
if (data.buddy_ids && data.buddy_ids.length > 0) {
|
||||
const tags = data.buddy_ids.map(buddyId => ({
|
||||
tasting_id: tasting.id,
|
||||
buddy_id: buddyId
|
||||
}));
|
||||
const { error: tagError } = await supabase
|
||||
.from('tasting_tags')
|
||||
.insert(tags);
|
||||
|
||||
if (tagError) {
|
||||
console.error('Error adding tasting tags:', tagError);
|
||||
// We don't throw here to not fail the whole tasting save,
|
||||
// but in a real app we might want more robust error handling
|
||||
}
|
||||
}
|
||||
|
||||
revalidatePath(`/bottles/${data.bottle_id}`);
|
||||
|
||||
return { success: true, data: tasting };
|
||||
|
||||
Reference in New Issue
Block a user