work on team enrollment

This commit is contained in:
yohlo
2025-09-16 09:24:21 -05:00
parent 9a105b30c6
commit cde74a04d5
45 changed files with 1244 additions and 457 deletions

View File

@@ -5,6 +5,7 @@ import { z } from "zod";
import { toServerResult } from "@/lib/tanstack-query/utils/to-server-result";
import { teamInputSchema, teamUpdateSchema } from "./types";
import { logger } from "@/lib/logger";
import { Match } from "../matches/types";
export const listTeamInfos = createServerFn()
@@ -55,13 +56,11 @@ export const updateTeam = createServerFn()
const userId = context.userAuthId;
const isAdmin = context.roles.includes("Admin");
// Get the team to verify ownership
const team = await pbAdmin.getTeam(id);
if (!team) {
throw new Error("Team not found");
}
// Check if user has permission to update this team
const isPlayerOnTeam = team.players.some(player => player.id === userId);
if (!isAdmin && !isPlayerOnTeam) {
throw new Error("You can only update teams that you are a member of");
@@ -78,3 +77,10 @@ export const getTeamStats = createServerFn()
.handler(async ({ data: teamId }) =>
toServerResult(() => pbAdmin.getTeamStats(teamId))
);
export const getTeamMatches = createServerFn()
.validator(z.string())
.middleware([superTokensFunctionMiddleware])
.handler(async ({ data }) =>
toServerResult<Match[]>(async () => await pbAdmin.getTeamMatches(data))
);