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 });
}
}
+18
View File
@@ -0,0 +1,18 @@
import { db } from '@/lib/db';
import { NextResponse } from 'next/server';
export async function GET() {
try {
const { rows } = await db.query(`
SELECT se.*,
(SELECT COUNT(*) FROM social_event_reservations ser WHERE ser.social_event_id = se.id) as reservation_count
FROM social_events se
WHERE se.active = true
ORDER BY se.sort_order, se.date, se.id
`);
return NextResponse.json({ data: rows });
} catch (error: any) {
console.error('GET /api/social_events/public error:', error);
return NextResponse.json({ error: error.message || 'Failed to load events' }, { status: 500 });
}
}
+37
View File
@@ -0,0 +1,37 @@
import { NextRequest, NextResponse } from 'next/server';
import { requireRole } from '@/lib/auth';
import { db } from '@/lib/db';
export async function GET() {
try {
await requireRole('admin');
const { rows } = await db.query(`
SELECT se.*,
(SELECT COUNT(*) FROM social_event_reservations ser WHERE ser.social_event_id = se.id) as reservation_count
FROM social_events se
ORDER BY se.sort_order, se.date, se.id
`);
return NextResponse.json({ data: rows });
} catch (error: any) {
console.error('GET /api/social_events error:', error);
return NextResponse.json({ error: error.message || 'Unauthorized' }, { status: 401 });
}
}
export async function POST(request: NextRequest) {
try {
await requireRole('admin');
const body = await request.json();
const { name, description, price, date, photos, featured_photo, active, sort_order } = body;
const { rows } = await db.query(
`INSERT INTO social_events (name, description, price, date, photos, featured_photo, active, sort_order)
VALUES ($1, $2, $3, $4, $5, $6, $7, $8)
RETURNING *`,
[name, description || '', price || null, date || null, photos || [], featured_photo || null, active !== false, sort_order || 0]
);
return NextResponse.json({ data: rows[0] });
} catch (error: any) {
console.error('POST /api/social_events error:', error);
return NextResponse.json({ error: error.message || 'Failed to create social event' }, { status: 500 });
}
}