mirror of
https://github.com/arthur-pbty/binouz.git
synced 2026-06-03 23:36:27 +02:00
b7010a1704
- Implemented AuthButton component for Discord sign-in and sign-out functionality. - Created CopyButton component for copying server IP addresses. - Developed EventCard and GradeCard components for displaying events and grades. - Added Footer and Navbar components for site navigation and information. - Introduced PurchaseButton for handling grade purchases with Stripe integration. - Created SectionHeader component for consistent section titles. - Implemented session management with SessionProvider for NextAuth. - Set up PostgreSQL database with Docker and Prisma for data management. - Added admin guard functionality to restrict access to certain routes. - Configured NextAuth with Discord provider for user authentication. - Defined Prisma schema for user, admin, grade, event, and purchase models. - Seeded database with initial grades and events data. - Added SVG hero image for the landing page. - Extended NextAuth types to include additional user properties.
39 lines
1.1 KiB
TypeScript
39 lines
1.1 KiB
TypeScript
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(),
|
|
});
|
|
}
|