stats reorg, upcoming refinement
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { logger } from "@/lib/logger";
|
||||
import PocketBase from "pocketbase";
|
||||
import { transformTeam, transformTeamInfo } from "@/lib/pocketbase/util/transform-types";
|
||||
import { Team, TeamInfo, TeamInput, TeamUpdateInput } from "@/features/teams/types";
|
||||
import { Team, TeamInfo, TeamInput, TeamUpdateInput, TeamStats } from "@/features/teams/types";
|
||||
|
||||
export function createTeamsService(pb: PocketBase) {
|
||||
return {
|
||||
@@ -64,7 +64,7 @@ export function createTeamsService(pb: PocketBase) {
|
||||
|
||||
async updateTeam(id: string, data: TeamUpdateInput): Promise<Team> {
|
||||
logger.info("PocketBase | Updating team", { id, updates: Object.keys(data) });
|
||||
|
||||
|
||||
try {
|
||||
const existingTeam = await pb.collection("teams").getOne(id).catch(() => null);
|
||||
if (!existingTeam) {
|
||||
@@ -72,7 +72,7 @@ export function createTeamsService(pb: PocketBase) {
|
||||
}
|
||||
|
||||
const result = await pb.collection("teams").update(id, data);
|
||||
|
||||
|
||||
return transformTeam(await pb.collection("teams").getOne(result.id, {
|
||||
expand: "players, tournaments"
|
||||
}));
|
||||
@@ -81,5 +81,16 @@ export function createTeamsService(pb: PocketBase) {
|
||||
throw error;
|
||||
}
|
||||
},
|
||||
|
||||
async getTeamStats(id: string): Promise<TeamStats | null> {
|
||||
logger.info("PocketBase | Getting team stats", id);
|
||||
try {
|
||||
const result = await pb.collection("team_stats").getFirstListItem(`team_id="${id}"`);
|
||||
return result as TeamStats;
|
||||
} catch (error) {
|
||||
logger.info("PocketBase | No team stats found", id);
|
||||
return null;
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user