feat: implement variable team matchups with partner rotation
- Add manual team entry for permanent teams in Matchups tab - Rename 'Teams' tab to 'Matchups' for clarity - Implement partner rotation strategies (minimize_repeat, maximize_even, elo_based) - Track partnerships across rounds to minimize repeat pairings - Fix unit tests for team configuration and ELO calculations - Add E2E test for 9+ participant tournaments with variable matchups Key changes: - TeamsSection.tsx: Added router.refresh(), manual team entry, and matchup display - schedule-generator.ts: Enhanced generateVariableRoundRobin to track partnerships - team-generator.ts: Fixed partnership frequency tracking across rounds - API routes: Updated to support variable team durability with rotation strategies
This commit is contained in:
@@ -2,6 +2,54 @@ import { NextResponse } from "next/server";
|
||||
import { prisma } from "@/lib/prisma";
|
||||
import { canManageTournament } from "@/lib/permissions";
|
||||
|
||||
/**
|
||||
* GET /api/tournaments/[id]/participants
|
||||
*
|
||||
* Get all participants for a tournament
|
||||
*/
|
||||
export async function GET(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
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 }
|
||||
);
|
||||
}
|
||||
|
||||
// Fetch participants with player details
|
||||
const participants = await prisma.eventParticipant.findMany({
|
||||
where: { eventId: tournamentId },
|
||||
include: {
|
||||
player: true,
|
||||
},
|
||||
orderBy: { registrationDate: 'desc' },
|
||||
});
|
||||
|
||||
return NextResponse.json({ participants });
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch participants:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to fetch participants" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
@@ -106,3 +154,63 @@ export async function POST(
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* DELETE /api/tournaments/[id]/participants
|
||||
*
|
||||
* Remove participants from a tournament
|
||||
*/
|
||||
export async function DELETE(
|
||||
request: Request,
|
||||
{ params }: { params: Promise<{ id: string }> }
|
||||
) {
|
||||
try {
|
||||
const { id } = await params
|
||||
const tournamentId = parseInt(id, 10);
|
||||
|
||||
if (isNaN(tournamentId)) {
|
||||
return NextResponse.json(
|
||||
{ error: "Invalid tournament ID" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const body = await request.json();
|
||||
const { playerIds } = body;
|
||||
|
||||
if (!playerIds || !Array.isArray(playerIds)) {
|
||||
return NextResponse.json(
|
||||
{ error: "playerIds array is required" },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
// Check permissions
|
||||
const permission = await canManageTournament(tournamentId);
|
||||
if (!permission.allowed) {
|
||||
return NextResponse.json(
|
||||
{ error: permission.reason || 'Insufficient permissions' },
|
||||
{ status: 403 }
|
||||
);
|
||||
}
|
||||
|
||||
// Remove participants
|
||||
const deleted = await prisma.eventParticipant.deleteMany({
|
||||
where: {
|
||||
eventId: tournamentId,
|
||||
playerId: { in: playerIds },
|
||||
},
|
||||
});
|
||||
|
||||
return NextResponse.json({
|
||||
success: true,
|
||||
deleted: deleted.count,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to remove participants:", error);
|
||||
return NextResponse.json(
|
||||
{ error: "Failed to remove participants" },
|
||||
{ status: 500 }
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user