better brackets, info types
This commit is contained in:
@@ -1,32 +1,32 @@
|
||||
import { logger } from "@/lib/logger";
|
||||
import type {
|
||||
Tournament,
|
||||
TournamentInfo,
|
||||
TournamentInput,
|
||||
TournamentUpdateInput,
|
||||
} from "@/features/tournaments/types";
|
||||
import type { Team } from "@/features/teams/types";
|
||||
import PocketBase from "pocketbase";
|
||||
import { transformTournament } from "@/lib/pocketbase/util/transform-types";
|
||||
import { transformTournament, transformTournamentInfo } from "@/lib/pocketbase/util/transform-types";
|
||||
import { transformTeam } from "@/lib/pocketbase/util/transform-types";
|
||||
|
||||
export function createTournamentsService(pb: PocketBase) {
|
||||
return {
|
||||
async getTournament(id: string): Promise<Tournament | null> {
|
||||
logger.info("PocketBase | Getting tournament", id);
|
||||
async getTournament(id: string): Promise<Tournament> {
|
||||
const result = await pb.collection("tournaments").getOne(id, {
|
||||
expand: "teams, teams.players",
|
||||
expand: "teams, teams.players, matches, matches.tournament",
|
||||
});
|
||||
return transformTournament(result);
|
||||
},
|
||||
async listTournaments(): Promise<Tournament[]> {
|
||||
async listTournaments(): Promise<TournamentInfo[]> {
|
||||
const result = await pb
|
||||
.collection("tournaments")
|
||||
.getFullList<Tournament>({
|
||||
fields: "id,name,start_time,end_time,logo,created",
|
||||
.getFullList({
|
||||
fields: "id,name,location,start_time,end_time,logo",
|
||||
sort: "-created",
|
||||
});
|
||||
|
||||
return result.map(transformTournament);
|
||||
return result.map(transformTournamentInfo);
|
||||
},
|
||||
async createTournament(data: TournamentInput): Promise<Tournament> {
|
||||
const result = await pb
|
||||
@@ -79,6 +79,18 @@ export function createTournamentsService(pb: PocketBase) {
|
||||
|
||||
return transformTournament(result);
|
||||
},
|
||||
async updateTournamentMatches(
|
||||
tournamentId: string,
|
||||
matchIds: string[]
|
||||
): Promise<Tournament> {
|
||||
logger.info("PocketBase | Updating tournament matches", { tournamentId, matchCount: matchIds.length });
|
||||
const result = await pb
|
||||
.collection("tournaments")
|
||||
.update<Tournament>(tournamentId, {
|
||||
matches: matchIds
|
||||
});
|
||||
return transformTournament(result);
|
||||
},
|
||||
async getUnenrolledTeams(tournamentId: string): Promise<Team[]> {
|
||||
try {
|
||||
logger.info(
|
||||
|
||||
Reference in New Issue
Block a user