free agents
This commit is contained in:
@@ -83,4 +83,39 @@ export const getUnenrolledTeams = createServerFn()
|
||||
.middleware([superTokensAdminFunctionMiddleware])
|
||||
.handler(async ({ data: tournamentId }) =>
|
||||
toServerResult(() => pbAdmin.getUnenrolledTeams(tournamentId))
|
||||
);
|
||||
);
|
||||
|
||||
export const getFreeAgents = createServerFn()
|
||||
.validator(z.string())
|
||||
.middleware([superTokensAdminFunctionMiddleware])
|
||||
.handler(async ({ data: tournamentId }) =>
|
||||
toServerResult(() => pbAdmin.getFreeAgents(tournamentId))
|
||||
);
|
||||
|
||||
export const enrollFreeAgent = createServerFn()
|
||||
.validator(z.object({ phone: z.string(), tournamentId: z.string() }))
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async ({ context, data }) =>
|
||||
toServerResult(async () => {
|
||||
const userAuthId = context.userAuthId;
|
||||
const player = await pbAdmin.getPlayerByAuthId(userAuthId);
|
||||
if (!player) throw new Error("Player not found");
|
||||
|
||||
await pbAdmin.enrollFreeAgent(player.id, data.phone, data.tournamentId);
|
||||
logger.info('Player enrolled as free agent', { playerId: player.id, phone: data.phone });
|
||||
})
|
||||
);
|
||||
|
||||
export const unenrollFreeAgent = createServerFn()
|
||||
.validator(z.object({ tournamentId: z.string() }))
|
||||
.middleware([superTokensFunctionMiddleware])
|
||||
.handler(async ({ context, data }) =>
|
||||
toServerResult(async () => {
|
||||
const userAuthId = context.userAuthId;
|
||||
const player = await pbAdmin.getPlayerByAuthId(userAuthId);
|
||||
if (!player) throw new Error("Player not found");
|
||||
|
||||
await pbAdmin.unenrollFreeAgent(player.id, data.tournamentId);
|
||||
logger.info('Player unenrolled as free agent', { playerId: player.id });
|
||||
})
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user