refactor(api): update all API routes to use new player field names

This commit is contained in:
2026-04-03 21:03:51 -07:00
parent e5f679e54c
commit 1f7d589698
11 changed files with 103 additions and 591 deletions
@@ -51,91 +51,15 @@ export async function POST(
const isTeamTournament = tournament.tournamentType === "team";
// For team tournaments, pair players into teams
if (isTeamTournament) {
if (playerIds.length % 2 !== 0) {
return NextResponse.json(
{ error: "Team tournaments require an even number of players" },
{ status: 400 }
);
}
// Create teams from consecutive pairs
const teams = [];
for (let i = 0; i < playerIds.length; i += 2) {
const player1Id = playerIds[i];
const player2Id = playerIds[i + 1];
// Check if team already exists
const existingTeam = await prisma.team.findFirst({
where: {
eventId: tournamentId,
OR: [
{ AND: [{ player1Id }, { player2Id }] },
{ AND: [{ player1Id: player2Id }, { player2Id: player1Id }] },
],
},
});
let team;
if (existingTeam) {
team = existingTeam;
} else {
team = await prisma.team.create({
data: {
eventId: tournamentId,
player1Id,
player2Id,
},
});
}
// Create participants linked to this team
const participant1 = await prisma.eventParticipant.upsert({
where: {
eventId_playerId: {
eventId: tournamentId,
playerId: player1Id,
},
},
update: { teamId: team.id },
create: {
eventId: tournamentId,
playerId: player1Id,
teamId: team.id,
status: "registered",
registrationDate: new Date(),
},
});
const participant2 = await prisma.eventParticipant.upsert({
where: {
eventId_playerId: {
eventId: tournamentId,
playerId: player2Id,
},
},
update: { teamId: team.id },
create: {
eventId: tournamentId,
playerId: player2Id,
teamId: team.id,
status: "registered",
registrationDate: new Date(),
},
});
teams.push({ team, participants: [participant1, participant2] });
}
return NextResponse.json({
success: true,
teamsCreated: teams.length,
teams,
});
// For team tournaments, validate even number of players
if (isTeamTournament && playerIds.length % 2 !== 0) {
return NextResponse.json(
{ error: "Team tournaments require an even number of players" },
{ status: 400 }
);
}
// Individual tournament - just add participants
// Add participants - teams will be generated later during schedule generation
const participants = await Promise.all(
playerIds.map(async (playerId: number) => {
try {