import { db } from "@/lib/db"; import { requireAdmin } from "@/lib/admin"; export const dynamic = "force-dynamic"; export async function GET() { const guard = await requireAdmin(); if (!guard.ok) return guard.response; const events = await db.event.findMany({ orderBy: { eventDate: "asc" } }); return Response.json(events); } export async function POST(request: Request) { const guard = await requireAdmin(); if (!guard.ok) return guard.response; const body = await request.json(); const title = body?.title?.toString().trim(); const description = body?.description?.toString().trim(); const eventDateValue = body?.eventDate?.toString(); const eventDate = eventDateValue ? new Date(eventDateValue) : null; if (!title || !description || !eventDate || Number.isNaN(eventDate.getTime())) { return Response.json({ error: "Invalid payload" }, { status: 400 }); } const event = await db.event.create({ data: { title, description, eventDate }, }); return Response.json({ id: event.id, title: event.title, description: event.description, eventDate: event.eventDate.toISOString(), }); }