import { NextResponse } from "next/server"; import { prisma } from "@/lib/prisma"; import { canManageTournament } from "@/lib/permissions"; interface RouteParams { params: Promise<{ id: string; }>; } /** * GET /api/tournaments/[id]/matches * * Get all matches for a tournament */ export async function GET(_request: Request, { params }: RouteParams) { try { const { id } = await params; const tournamentId = parseInt(id, 10); if (isNaN(tournamentId)) { return NextResponse.json( { error: "Invalid tournament ID" }, { status: 400 } ); } // Check permissions const permission = await canManageTournament(tournamentId); if (!permission.allowed) { return NextResponse.json( { error: permission.reason || 'Insufficient permissions' }, { status: 403 } ); } // Get matches for this tournament const matches = await prisma.match.findMany({ where: { eventId: tournamentId }, include: { player1P1: true, player1P2: true, player2P1: true, player2P2: true, }, orderBy: { playedAt: "desc" }, }); return NextResponse.json({ matches }); } catch (error) { console.error("Failed to fetch matches:", error); return NextResponse.json( { error: "Failed to fetch matches" }, { status: 500 } ); } }