better brackets, info types
This commit is contained in:
@@ -1,18 +1,75 @@
|
||||
import { Player } from "@/features/players/types";
|
||||
import { Team } from "@/features/teams/types";
|
||||
import { Tournament } from "@/features/tournaments/types";
|
||||
import { Match } from "@/features/matches/types";
|
||||
import { Player, PlayerInfo } from "@/features/players/types";
|
||||
import { Team, TeamInfo } from "@/features/teams/types";
|
||||
import { Tournament, TournamentInfo } from "@/features/tournaments/types";
|
||||
|
||||
// pocketbase does this weird thing with relations where it puts them under a seperate "expand" field
|
||||
// this file transforms raw pocketbase results to our types
|
||||
|
||||
export function transformPlayerInfo(record: any): PlayerInfo {
|
||||
return {
|
||||
id: record.id,
|
||||
first_name: record.first_name,
|
||||
last_name: record.last_name,
|
||||
};
|
||||
}
|
||||
|
||||
export function transformTeamInfo(record: any): TeamInfo {
|
||||
const players = record.expand?.players?.map(transformPlayerInfo) ?? [];
|
||||
return {
|
||||
id: record.id,
|
||||
name: record.name,
|
||||
primary_color: record.primary_color,
|
||||
accent_color: record.accent_color,
|
||||
players,
|
||||
};
|
||||
}
|
||||
|
||||
export const transformMatch = (record: any): Match => {
|
||||
return {
|
||||
id: record.id,
|
||||
order: record.name,
|
||||
lid: record.lid,
|
||||
reset: record.reset,
|
||||
round: record.round,
|
||||
home_cups: record.home_cups,
|
||||
away_cups: record.away_cups,
|
||||
ot_count: record.ot_count,
|
||||
start_time: record.start_time,
|
||||
end_time: record.end_time,
|
||||
bye: record.bye,
|
||||
home_from_lid: record.home_from_lid,
|
||||
away_from_lid: record.away_from_lid,
|
||||
home_from_loser: record.home_from_loser,
|
||||
away_from_loser: record.away_from_loser,
|
||||
is_losers_bracket: record.is_losers_bracket,
|
||||
tournament: transformTournamentInfo(record.expand?.tournament),
|
||||
home: record.expand?.home ? transformTeamInfo(record.expand.home) : undefined,
|
||||
away: record.expand?.away ? transformTeamInfo(record.expand.away) : undefined,
|
||||
created: record.created,
|
||||
updated: record.updated,
|
||||
home_seed: record.home_seed,
|
||||
away_seed: record.away_seed,
|
||||
};
|
||||
}
|
||||
|
||||
export const transformTournamentInfo = (record: any): TournamentInfo => {
|
||||
return {
|
||||
id: record.id,
|
||||
name: record.name,
|
||||
location: record.location,
|
||||
start_time: record.start_time,
|
||||
logo: record.logo,
|
||||
};
|
||||
}
|
||||
|
||||
export function transformPlayer(record: any): Player {
|
||||
const sadf: string[] = [];
|
||||
const teams =
|
||||
record.expand?.teams
|
||||
?.sort((a: Team, b: Team) =>
|
||||
?.sort((a: any, b: any) =>
|
||||
new Date(a.created) < new Date(b.created) ? -1 : 0
|
||||
)
|
||||
?.map(transformTeam) ?? [];
|
||||
?.map(transformTeamInfo) ?? [];
|
||||
|
||||
return {
|
||||
id: record.id!,
|
||||
@@ -28,16 +85,16 @@ export function transformPlayer(record: any): Player {
|
||||
export function transformTeam(record: any): Team {
|
||||
const players =
|
||||
record.expand?.players
|
||||
?.sort((a: Player, b: Player) =>
|
||||
?.sort((a: any, b: any) =>
|
||||
new Date(a.created!) < new Date(b.created!) ? -1 : 0
|
||||
)
|
||||
?.map(transformPlayer) ?? [];
|
||||
?.map(transformPlayerInfo) ?? [];
|
||||
const tournaments =
|
||||
record.expand?.tournaments
|
||||
?.sort((a: Tournament, b: Tournament) =>
|
||||
?.sort((a: any, b: any) =>
|
||||
new Date(a.created!) < new Date(b.created!) ? -1 : 0
|
||||
)
|
||||
?.map(transformTournament) ?? [];
|
||||
?.map(transformTournamentInfo) ?? [];
|
||||
|
||||
return {
|
||||
id: record.id,
|
||||
@@ -63,11 +120,18 @@ export function transformTeam(record: any): Team {
|
||||
export function transformTournament(record: any): Tournament {
|
||||
const teams =
|
||||
record.expand?.teams
|
||||
?.sort((a: Team, b: Team) =>
|
||||
?.sort((a: any, b: any) =>
|
||||
new Date(a.created) < new Date(b.created) ? -1 : 0
|
||||
)
|
||||
?.map(transformTeam) ?? [];
|
||||
?.map(transformTeamInfo) ?? [];
|
||||
|
||||
const matches =
|
||||
record.expand?.matches
|
||||
?.sort((a: any, b: any) =>
|
||||
a.lid - b.lid ? -1 : 0
|
||||
)
|
||||
?.map(transformMatch) ?? [];
|
||||
|
||||
return {
|
||||
id: record.id,
|
||||
name: record.name,
|
||||
@@ -81,5 +145,6 @@ export function transformTournament(record: any): Tournament {
|
||||
created: record.created,
|
||||
updated: record.updated,
|
||||
teams,
|
||||
matches
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user