Merge branch 'perf' into development
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 { emitServerEvent } from "@/lib/events/emitter";
|
||||
import brackets from "@/features/bracket/utils";
|
||||
import { MatchInput } from "@/features/matches/types";
|
||||
import { generateSingleEliminationBracket } from "./utils/bracket-generator";
|
||||
@@ -19,8 +20,12 @@ export const listTournaments = createServerFn()
|
||||
export const createTournament = createServerFn()
|
||||
.validator(tournamentInputSchema)
|
||||
.middleware([superTokensAdminFunctionMiddleware, serverFnLoggingMiddleware])
|
||||
.handler(async ({ data }) =>
|
||||
toServerResult(() => pbAdmin.createTournament(data))
|
||||
.handler(async ({ data }) =>
|
||||
toServerResult(async () => {
|
||||
const tournament = await pbAdmin.createTournament(data);
|
||||
emitServerEvent({ type: "tournament", tournamentId: tournament.id });
|
||||
return tournament;
|
||||
})
|
||||
);
|
||||
|
||||
export const updateTournament = createServerFn()
|
||||
@@ -29,8 +34,12 @@ export const updateTournament = createServerFn()
|
||||
updates: tournamentInputSchema.partial()
|
||||
}))
|
||||
.middleware([superTokensAdminFunctionMiddleware, serverFnLoggingMiddleware])
|
||||
.handler(async ({ data }) =>
|
||||
toServerResult(() => pbAdmin.updateTournament(data.id, data.updates))
|
||||
.handler(async ({ data }) =>
|
||||
toServerResult(async () => {
|
||||
const tournament = await pbAdmin.updateTournament(data.id, data.updates);
|
||||
emitServerEvent({ type: "tournament", tournamentId: data.id });
|
||||
return tournament;
|
||||
})
|
||||
);
|
||||
|
||||
export const getTournament = createServerFn()
|
||||
@@ -76,6 +85,7 @@ export const enrollTeam = createServerFn()
|
||||
|
||||
logger.info('Enrolling team in tournament', { tournamentId, teamId, userId });
|
||||
const tournament = await pbAdmin.enrollTeam(tournamentId, teamId);
|
||||
emitServerEvent({ type: "tournament", tournamentId });
|
||||
return tournament;
|
||||
})
|
||||
);
|
||||
@@ -86,8 +96,12 @@ export const unenrollTeam = createServerFn()
|
||||
teamId: z.string()
|
||||
}))
|
||||
.middleware([superTokensFunctionMiddleware, serverFnLoggingMiddleware])
|
||||
.handler(async ({ data: { tournamentId, teamId }, context }) =>
|
||||
toServerResult(() => pbAdmin.unenrollTeam(tournamentId, teamId))
|
||||
.handler(async ({ data: { tournamentId, teamId }, context }) =>
|
||||
toServerResult(async () => {
|
||||
const result = await pbAdmin.unenrollTeam(tournamentId, teamId);
|
||||
emitServerEvent({ type: "tournament", tournamentId });
|
||||
return result;
|
||||
})
|
||||
);
|
||||
|
||||
export const getUnenrolledTeams = createServerFn()
|
||||
@@ -115,6 +129,7 @@ export const enrollFreeAgent = createServerFn()
|
||||
|
||||
await pbAdmin.enrollFreeAgent(player.id, data.phone, data.tournamentId);
|
||||
logger.info('Player enrolled as free agent', { playerId: player.id, phone: data.phone });
|
||||
emitServerEvent({ type: "tournament", tournamentId: data.tournamentId });
|
||||
})
|
||||
);
|
||||
|
||||
@@ -129,6 +144,7 @@ export const unenrollFreeAgent = createServerFn()
|
||||
|
||||
await pbAdmin.unenrollFreeAgent(player.id, data.tournamentId);
|
||||
logger.info('Player unenrolled as free agent', { playerId: player.id });
|
||||
emitServerEvent({ type: "tournament", tournamentId: data.tournamentId });
|
||||
})
|
||||
);
|
||||
|
||||
@@ -382,6 +398,9 @@ export const confirmTeamAssignments = createServerFn()
|
||||
newCount: createdTeams.length - reusedCount
|
||||
});
|
||||
|
||||
emitServerEvent({ type: "team" });
|
||||
emitServerEvent({ type: "tournament", tournamentId: data.tournamentId });
|
||||
|
||||
return { teams: createdTeams };
|
||||
})
|
||||
);
|
||||
@@ -702,6 +721,8 @@ export const generateKnockoutBracket = createServerFn()
|
||||
qualifiedTeamCount: qualifiedTeams.length
|
||||
});
|
||||
|
||||
emitServerEvent({ type: "tournament", tournamentId: data.tournamentId });
|
||||
|
||||
return {
|
||||
tournament,
|
||||
matchCount: createdMatches.length,
|
||||
@@ -720,6 +741,7 @@ export const adminEnrollPlayer = createServerFn()
|
||||
toServerResult(async () => {
|
||||
await pbAdmin.enrollFreeAgent(data.playerId, "", data.tournamentId);
|
||||
logger.info('Admin enrolled player', { playerId: data.playerId, tournamentId: data.tournamentId });
|
||||
emitServerEvent({ type: "tournament", tournamentId: data.tournamentId });
|
||||
})
|
||||
);
|
||||
|
||||
@@ -733,6 +755,7 @@ export const adminUnenrollPlayer = createServerFn()
|
||||
toServerResult(async () => {
|
||||
await pbAdmin.unenrollFreeAgent(data.playerId, data.tournamentId);
|
||||
logger.info('Admin unenrolled player', { playerId: data.playerId, tournamentId: data.tournamentId });
|
||||
emitServerEvent({ type: "tournament", tournamentId: data.tournamentId });
|
||||
})
|
||||
);
|
||||
|
||||
@@ -881,6 +904,8 @@ export const generateGroupStage = createServerFn()
|
||||
totalMatchCount: createdMatches.length
|
||||
});
|
||||
|
||||
emitServerEvent({ type: "tournament", tournamentId: data.tournamentId });
|
||||
|
||||
return {
|
||||
tournament,
|
||||
groups: createdGroups,
|
||||
|
||||
Reference in New Issue
Block a user