better brackets, info types
This commit is contained in:
39
src/lib/pocketbase/services/matches.ts
Normal file
39
src/lib/pocketbase/services/matches.ts
Normal 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))
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
Reference in New Issue
Block a user