better brackets, info types

This commit is contained in:
yohlo
2025-09-07 00:52:28 -05:00
parent cb83ea06fa
commit 2396464a19
36 changed files with 678 additions and 657 deletions

View File

@@ -0,0 +1,39 @@
import { logger } from "@/lib/logger";
import type { Match, MatchInput } from "@/features/matches/types";
import type PocketBase from "pocketbase";
export function createMatchesService(pb: PocketBase) {
return {
async createMatch(data: MatchInput): Promise<Match> {
logger.info("PocketBase | Creating match", data);
const result = await pb.collection("matches").create<Match>(data);
return result;
},
async createMatches(matches: MatchInput[]): Promise<Match[]> {
logger.info("PocketBase | Creating multiple matches", { count: matches.length });
const results = await Promise.all(
matches.map(match => pb.collection("matches").create<Match>(match))
);
return results;
},
async updateMatch(id: string, data: Partial<MatchInput>): Promise<Match> {
logger.info("PocketBase | Updating match", { id, data });
const result = await pb.collection("matches").update<Match>(id, data);
return result;
},
async deleteMatchesByTournament(tournamentId: string): Promise<void> {
logger.info("PocketBase | Deleting matches for tournament", tournamentId);
const matches = await pb.collection("matches").getFullList({
filter: `tournament = "${tournamentId}"`,
fields: "id",
});
await Promise.all(
matches.map(match => pb.collection("matches").delete(match.id))
);
},
};
}