groups init

This commit is contained in:
yohlo
2026-02-25 19:54:51 -06:00
parent 2dd3e5b170
commit f83a7d69c8
17 changed files with 1306 additions and 17 deletions

View File

@@ -0,0 +1,46 @@
import { logger } from "@/lib/logger";
import PocketBase from "pocketbase";
import { Group } from "@/features/tournaments/types";
export interface GroupInput {
tournament: string;
name: string;
order: number;
teams: string[];
}
export function createGroupsService(pb: PocketBase) {
return {
async createGroup(data: GroupInput): Promise<Group> {
logger.info("PocketBase | Creating group", data);
const result = await pb.collection("groups").create(data);
return result as unknown as Group;
},
async getGroupsByTournament(tournamentId: string): Promise<Group[]> {
logger.info("PocketBase | Getting groups for tournament", { tournamentId });
const result = await pb.collection("groups").getFullList({
filter: `tournament = "${tournamentId}"`,
sort: "order",
expand: "teams,teams.players"
});
return result as unknown as Group[];
},
async deleteGroup(groupId: string): Promise<void> {
logger.info("PocketBase | Deleting group", { groupId });
await pb.collection("groups").delete(groupId);
},
async deleteGroupsByTournament(tournamentId: string): Promise<void> {
logger.info("PocketBase | Deleting all groups for tournament", { tournamentId });
const groups = await pb.collection("groups").getFullList({
filter: `tournament = "${tournamentId}"`
});
for (const group of groups) {
await pb.collection("groups").delete(group.id);
}
}
};
}

View File

@@ -14,17 +14,23 @@ import { PlayerInfo } from "@/features/players/types";
export function createTournamentsService(pb: PocketBase) {
return {
async getTournament(id: string, isAdmin: boolean = false): Promise<Tournament> {
const [tournamentResult, teamStatsResult] = await Promise.all([
const [tournamentResult, teamStatsResult, groupsResult] = await Promise.all([
pb.collection("tournaments").getOne(id, {
expand: "teams, teams.players, matches, matches.tournament, matches.home, matches.away, matches.home.players, matches.away.players",
}),
pb.collection("team_stats_per_tournament").getFullList({
filter: `tournament_id = "${id}"`,
sort: "-wins,-total_cups_made"
}),
pb.collection("groups").getFullList({
filter: `tournament = "${id}"`,
sort: "order",
expand: "teams, teams.players"
})
]);
tournamentResult.team_stats = teamStatsResult;
tournamentResult.groups = groupsResult;
return transformTournament(tournamentResult, isAdmin);
},