import { NextRequest, NextResponse } from "next/server"; import { db } from "@/lib/db"; import { getApiUser } from "@/lib/apiAuth"; export async function GET(req: NextRequest, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; const match = await db.match.findUnique({ where: { id }, include: { homeTeam: true, awayTeam: true, playerStats: { include: { player: true } } }, }); if (!match) return NextResponse.json({ error: "Not found" }, { status: 404 }); return NextResponse.json(match); } export async function PUT(req: NextRequest, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; const apiUser = await getApiUser(req); if (!apiUser || apiUser.role !== "ADMIN") return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); const body = await req.json(); const match = await db.match.update({ where: { id }, data: { ...body, matchDate: new Date(body.matchDate), }, }); return NextResponse.json(match); } export async function DELETE(req: NextRequest, { params }: { params: Promise<{ id: string }> }) { const { id } = await params; const apiUser = await getApiUser(req); if (!apiUser || apiUser.role !== "ADMIN") return NextResponse.json({ error: "Unauthorized" }, { status: 401 }); await db.match.delete({ where: { id } }); return NextResponse.json({ success: true }); }