import { NextRequest, NextResponse } from 'next/server'; import { requireRole } from '@/lib/auth'; import { db } from '@/lib/db'; export async function PUT(request: NextRequest, { params }: { params: { id: string } }) { try { await requireRole('admin'); const id = parseInt(params.id, 10); const body = await request.json(); const { name, description, price, date, photos, featured_photo, active, sort_order } = body; const { rows } = await db.query( `UPDATE social_events SET name=$1, description=$2, price=$3, date=$4, photos=$5, featured_photo=$6, active=$7, sort_order=$8 WHERE id=$9 RETURNING *`, [name, description || '', price || null, date || null, photos || [], featured_photo || null, active !== false, sort_order || 0, id] ); if (rows.length === 0) return NextResponse.json({ error: 'Not found' }, { status: 404 }); return NextResponse.json({ data: rows[0] }); } catch (error: any) { console.error('PUT /api/social_events/:id error:', error); return NextResponse.json({ error: error.message || 'Failed to update social event' }, { status: 500 }); } } export async function DELETE(request: NextRequest, { params }: { params: { id: string } }) { try { await requireRole('admin'); const id = parseInt(params.id, 10); await db.query('DELETE FROM social_events WHERE id=$1', [id]); return NextResponse.json({ ok: true }); } catch (error: any) { console.error('DELETE /api/social_events/:id error:', error); return NextResponse.json({ error: error.message || 'Failed to delete social event' }, { status: 500 }); } }