work on team enrollment
This commit is contained in:
@@ -65,10 +65,10 @@ export function createPlayersService(pb: PocketBase) {
|
||||
return result.map(transformPlayer);
|
||||
},
|
||||
|
||||
async getPlayerStats(playerId: string): Promise<PlayerStats[]> {
|
||||
const result = await pb.collection("player_stats").getFullList<PlayerStats>({
|
||||
filter: `player_id = "${playerId}"`,
|
||||
});
|
||||
async getPlayerStats(playerId: string): Promise<PlayerStats> {
|
||||
const result = await pb.collection("player_stats").getFirstListItem<PlayerStats>(
|
||||
`player_id = "${playerId}"`
|
||||
);
|
||||
return result;
|
||||
},
|
||||
|
||||
@@ -102,5 +102,56 @@ export function createPlayersService(pb: PocketBase) {
|
||||
|
||||
return result.map(transformMatch);
|
||||
},
|
||||
|
||||
async getUnenrolledPlayers(tournamentId: string): Promise<Player[]> {
|
||||
try {
|
||||
// Get the tournament with its enrolled teams
|
||||
const tournament = await pb.collection("tournaments").getOne(tournamentId, {
|
||||
fields: "teams",
|
||||
expand: "teams,teams.players"
|
||||
});
|
||||
|
||||
// Extract player IDs from all enrolled teams
|
||||
const enrolledPlayerIds: string[] = [];
|
||||
if (tournament.expand?.teams) {
|
||||
const teams = Array.isArray(tournament.expand.teams) ? tournament.expand.teams : [tournament.expand.teams];
|
||||
teams.forEach((team: any) => {
|
||||
if (team.expand?.players) {
|
||||
const players = Array.isArray(team.expand.players) ? team.expand.players : [team.expand.players];
|
||||
players.forEach((player: any) => {
|
||||
enrolledPlayerIds.push(player.id);
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// If no players are enrolled, return all players
|
||||
if (enrolledPlayerIds.length === 0) {
|
||||
const allPlayers = await pb.collection("players").getFullList<Player>({
|
||||
fields: "id,first_name,last_name,email",
|
||||
});
|
||||
return allPlayers.map(transformPlayer);
|
||||
}
|
||||
|
||||
// Build filter to exclude enrolled players
|
||||
const filter = enrolledPlayerIds
|
||||
.map((playerId: string) => `id != "${playerId}"`)
|
||||
.join(" && ");
|
||||
|
||||
const availablePlayers = await pb.collection("players").getFullList<Player>({
|
||||
filter,
|
||||
fields: "id,first_name,last_name,email",
|
||||
});
|
||||
|
||||
return availablePlayers.map(transformPlayer);
|
||||
} catch (error) {
|
||||
console.error("Error getting unenrolled players:", error);
|
||||
// Fallback to all players if there's an error
|
||||
const allPlayers = await pb.collection("players").getFullList<Player>({
|
||||
fields: "id,first_name,last_name,email",
|
||||
});
|
||||
return allPlayers.map(transformPlayer);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,7 +1,8 @@
|
||||
import { logger } from "@/lib/logger";
|
||||
import PocketBase from "pocketbase";
|
||||
import { transformTeam, transformTeamInfo } from "@/lib/pocketbase/util/transform-types";
|
||||
import { transformMatch, transformTeam, transformTeamInfo } from "@/lib/pocketbase/util/transform-types";
|
||||
import { Team, TeamInfo, TeamInput, TeamUpdateInput, TeamStats } from "@/features/teams/types";
|
||||
import { Match } from "@/features/matches/types";
|
||||
|
||||
export function createTeamsService(pb: PocketBase) {
|
||||
return {
|
||||
@@ -86,11 +87,23 @@ export function createTeamsService(pb: PocketBase) {
|
||||
logger.info("PocketBase | Getting team stats", id);
|
||||
try {
|
||||
const result = await pb.collection("team_stats").getFirstListItem(`team_id="${id}"`);
|
||||
return result as TeamStats;
|
||||
return result as unknown as TeamStats;
|
||||
} catch (error) {
|
||||
logger.info("PocketBase | No team stats found", id);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
|
||||
async getTeamMatches(teamId: string): Promise<Match[]> {
|
||||
const teamFilter = `home = "${teamId}" || away = "${teamId}"`
|
||||
|
||||
const result = await pb.collection("matches").getFullList({
|
||||
filter: `(${teamFilter}) && (status = "ended" || status = "started")`,
|
||||
sort: "-start_time",
|
||||
expand: "tournament,home,away",
|
||||
});
|
||||
|
||||
return result.map(transformMatch);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export const appInfo = {
|
||||
appName: 'Tanstack Start SuperTokens',
|
||||
appName: 'FLXN',
|
||||
apiDomain: import.meta.env.VITE_API_DOMAIN || 'http://localhost:3000',
|
||||
websiteDomain: import.meta.env.VITE_WEBSITE_DOMAIN || 'http://localhost:3000',
|
||||
apiBasePath: '/api/auth',
|
||||
|
||||
Reference in New Issue
Block a user