import { NextResponse } from 'next/server'; import { getSupabaseServerAdminClient } from '@kit/supabase/server-admin-client'; export async function POST(request: Request) { try { const body = await request.json(); const { accountId, firstName, lastName, email, phone, street, postalCode, city, dateOfBirth, message, } = body; if (!accountId || !firstName || !lastName || !email) { return NextResponse.json( { error: 'Konto-ID, Vorname, Nachname und E-Mail sind erforderlich', }, { status: 400 }, ); } if (!/^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(email)) { return NextResponse.json( { error: 'Ungültige E-Mail-Adresse' }, { status: 400 }, ); } const supabase = getSupabaseServerAdminClient(); const { error } = await supabase.from('membership_applications').insert({ account_id: accountId, first_name: firstName, last_name: lastName, email, phone: phone || null, street: street || null, postal_code: postalCode || null, city: city || null, date_of_birth: dateOfBirth || null, message: message || null, status: 'submitted', }); if (error) { console.error('[membership-apply] Insert error:', error.message); return NextResponse.json( { error: 'Bewerbung fehlgeschlagen' }, { status: 500 }, ); } return NextResponse.json({ success: true, message: 'Bewerbung erfolgreich eingereicht', }); } catch (err) { console.error('[membership-apply] Error:', err); return NextResponse.json({ error: 'Serverfehler' }, { status: 500 }); } }