feat: add player profiles, schedule, tournaments admin, and CSV upload API
This commit is contained in:
@@ -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 }
|
||||
)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user