33 lines
1.1 KiB
TypeScript
33 lines
1.1 KiB
TypeScript
import { logger } from "@/lib/logger";
|
|
import PocketBase from "pocketbase";
|
|
import { transformTeam, transformTeamInfo } from "@/lib/pocketbase/util/transform-types";
|
|
import { Team, TeamInfo } from "@/features/teams/types";
|
|
import { DataFetchOptions } from "./base";
|
|
|
|
export function createTeamsService(pb: PocketBase) {
|
|
return {
|
|
async getTeamInfo(id: string): Promise<TeamInfo> {
|
|
logger.info("PocketBase | Getting team info", id);
|
|
const result = await pb.collection("teams").getOne(id, {
|
|
fields: "id,name,primary_color,accent_color"
|
|
});
|
|
return transformTeamInfo(result);
|
|
},
|
|
|
|
async listTeamInfos(): Promise<TeamInfo[]> {
|
|
logger.info("PocketBase | Listing team infos");
|
|
const result = await pb.collection("teams").getFullList({
|
|
fields: "id,name,primary_color,accent_color"
|
|
});
|
|
return result.map(transformTeamInfo);
|
|
},
|
|
async getTeam(id: string): Promise<Team | null> {
|
|
logger.info("PocketBase | Getting team", id);
|
|
const result = await pb.collection("teams").getOne(id, {
|
|
expand: "players, tournaments",
|
|
});
|
|
return transformTeam(result);
|
|
},
|
|
};
|
|
}
|