improvements
This commit is contained in:
@@ -6,6 +6,7 @@ import { logger } from ".";
|
||||
import { z } from "zod";
|
||||
import { toServerResult } from "@/lib/tanstack-query/utils/to-server-result";
|
||||
import { serverFnLoggingMiddleware } from "@/utils/activities";
|
||||
import { fa } from "zod/v4/locales";
|
||||
|
||||
export const listTournaments = createServerFn()
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
@@ -64,6 +65,14 @@ export const enrollTeam = createServerFn()
|
||||
// throw new Error('You do not have permission to enroll this team');
|
||||
//}
|
||||
|
||||
const freeAgents = await pbAdmin.getFreeAgents(tournamentId);
|
||||
for (const player of team.players || []) {
|
||||
const isFreeAgent = freeAgents.some(fa => fa.player?.id === player.id);
|
||||
if (isFreeAgent) {
|
||||
await pbAdmin.unenrollFreeAgent(player.id, tournamentId);
|
||||
}
|
||||
}
|
||||
|
||||
logger.info('Enrolling team in tournament', { tournamentId, teamId, userId });
|
||||
const tournament = await pbAdmin.enrollTeam(tournamentId, teamId);
|
||||
return tournament;
|
||||
|
||||
Reference in New Issue
Block a user