some changes

This commit is contained in:
yohlo
2025-09-11 13:35:33 -05:00
parent c74da09bde
commit 22be6682dd
18 changed files with 113 additions and 68 deletions

View File

@@ -1,9 +1,18 @@
import { logger } from "@/lib/logger";
import type { Match, MatchInput } from "@/features/matches/types";
import type PocketBase from "pocketbase";
import { transformMatch } from "../util/transform-types";
export function createMatchesService(pb: PocketBase) {
return {
async getMatch(id: string): Promise<Match | null> {
logger.info("PocketBase | Getting match", id);
const result = await pb.collection("matches").getOne(id, {
expand: "tournament, home, away",
});
return transformMatch(result);
},
async createMatch(data: MatchInput): Promise<Match> {
logger.info("PocketBase | Creating match", data);
const result = await pb.collection("matches").create<Match>(data);
@@ -11,9 +20,11 @@ export function createMatchesService(pb: PocketBase) {
},
async createMatches(matches: MatchInput[]): Promise<Match[]> {
logger.info("PocketBase | Creating multiple matches", { count: matches.length });
logger.info("PocketBase | Creating multiple matches", {
count: matches.length,
});
const results = await Promise.all(
matches.map(match => pb.collection("matches").create<Match>(match))
matches.map((match) => pb.collection("matches").create<Match>(match))
);
return results;
},
@@ -30,10 +41,10 @@ export function createMatchesService(pb: PocketBase) {
filter: `tournament = "${tournamentId}"`,
fields: "id",
});
await Promise.all(
matches.map(match => pb.collection("matches").delete(match.id))
matches.map((match) => pb.collection("matches").delete(match.id))
);
},
};
}
}