Add Social Events tab with reservations

This commit is contained in:
2026-06-27 19:40:22 -05:00
parent 71ae322b3f
commit 744830c3cd
10 changed files with 939 additions and 138 deletions
+36
View File
@@ -0,0 +1,36 @@
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 });
}
}