feat: add player profiles, schedule, tournaments admin, and CSV upload API

This commit is contained in:
2026-03-27 14:54:26 -07:00
parent 66e4baa643
commit aaf11b877e
12 changed files with 1409 additions and 0 deletions
+68
View File
@@ -0,0 +1,68 @@
import { NextRequest, NextResponse } from "next/server"
import { prisma } from "@/lib/prisma"
import { auth } from "@/lib/auth"
export async function POST(request: NextRequest) {
const session = await auth()
if (!session) {
return NextResponse.json({ error: "Unauthorized" }, { status: 401 })
}
try {
const body = await request.json()
const { name, description, eventDate, format, maxParticipants } = body
if (!name) {
return NextResponse.json(
{ error: "Tournament name is required" },
{ status: 400 }
)
}
const tournament = await prisma.event.create({
data: {
name,
description: description || "",
eventDate: eventDate ? new Date(eventDate) : null,
format: format || "round_robin",
status: "planned",
maxParticipants: maxParticipants || null,
},
})
return NextResponse.json({ success: true, tournament })
} catch (error) {
console.error("Error creating tournament:", error)
return NextResponse.json(
{ error: "Failed to create tournament" },
{ status: 500 }
)
}
}
export async function GET() {
try {
const tournaments = await prisma.event.findMany({
include: {
participants: true,
teams: {
include: {
player1: true,
player2: true,
},
},
rounds: true,
},
orderBy: { createdAt: "desc" },
})
return NextResponse.json({ tournaments })
} catch (error) {
console.error("Error fetching tournaments:", error)
return NextResponse.json(
{ error: "Failed to fetch tournaments" },
{ status: 500 }
)
}
}