100 lines
4.4 KiB
TypeScript
100 lines
4.4 KiB
TypeScript
import { BaseApiClient } from '../base/BaseApiClient';
|
|
import type { AllLeaguesWithCapacityDTO } from '../../types/generated/AllLeaguesWithCapacityDTO';
|
|
import type { TotalLeaguesDTO } from '../../types/generated/TotalLeaguesDTO';
|
|
import type { LeagueStandingsDTO } from '../../types/generated/LeagueStandingsDTO';
|
|
import type { LeagueScheduleDTO } from '../../types/generated/LeagueScheduleDTO';
|
|
import type { LeagueMembershipsDTO } from '../../types/generated/LeagueMembershipsDTO';
|
|
import type { CreateLeagueInputDTO } from '../../types/generated/CreateLeagueInputDTO';
|
|
import type { CreateLeagueOutputDTO } from '../../types/generated/CreateLeagueOutputDTO';
|
|
import type { SponsorshipDetailDTO } from '../../types/generated/SponsorshipDetailDTO';
|
|
import type { RaceDTO } from '../../types/generated/RaceDTO';
|
|
import type { GetLeagueAdminConfigOutputDTO } from '../../types/generated/GetLeagueAdminConfigOutputDTO';
|
|
import type { LeagueScoringPresetDTO } from '../../types/generated/LeagueScoringPresetDTO';
|
|
import type { LeagueSeasonSummaryDTO } from '../../types/generated/LeagueSeasonSummaryDTO';
|
|
import type { AllLeaguesWithCapacityAndScoringDTO } from '../../types/AllLeaguesWithCapacityAndScoringDTO';
|
|
|
|
/**
|
|
* Leagues API Client
|
|
*
|
|
* Handles all league-related API operations.
|
|
*/
|
|
export class LeaguesApiClient extends BaseApiClient {
|
|
/** Get all leagues with capacity information */
|
|
getAllWithCapacity(): Promise<AllLeaguesWithCapacityDTO> {
|
|
return this.get<AllLeaguesWithCapacityDTO>('/leagues/all-with-capacity');
|
|
}
|
|
|
|
/** Get all leagues with capacity + scoring summary (for leagues page filters) */
|
|
getAllWithCapacityAndScoring(): Promise<AllLeaguesWithCapacityAndScoringDTO> {
|
|
return this.get<AllLeaguesWithCapacityAndScoringDTO>('/leagues/all-with-capacity-and-scoring');
|
|
}
|
|
|
|
/** Get total number of leagues */
|
|
getTotal(): Promise<TotalLeaguesDTO> {
|
|
return this.get<TotalLeaguesDTO>('/leagues/total-leagues');
|
|
}
|
|
|
|
/** Get league standings */
|
|
getStandings(leagueId: string): Promise<LeagueStandingsDTO> {
|
|
return this.get<LeagueStandingsDTO>(`/leagues/${leagueId}/standings`);
|
|
}
|
|
|
|
/** Get league schedule */
|
|
getSchedule(leagueId: string): Promise<LeagueScheduleDTO> {
|
|
return this.get<LeagueScheduleDTO>(`/leagues/${leagueId}/schedule`);
|
|
}
|
|
|
|
/** Get league memberships */
|
|
getMemberships(leagueId: string): Promise<LeagueMembershipsDTO> {
|
|
return this.get<LeagueMembershipsDTO>(`/leagues/${leagueId}/memberships`);
|
|
}
|
|
|
|
/** Create a new league */
|
|
create(input: CreateLeagueInputDTO): Promise<CreateLeagueOutputDTO> {
|
|
return this.post<CreateLeagueOutputDTO>('/leagues', input);
|
|
}
|
|
|
|
/** Remove a member from league */
|
|
removeMember(leagueId: string, performerDriverId: string, targetDriverId: string): Promise<{ success: boolean }> {
|
|
return this.patch<{ success: boolean }>(`/leagues/${leagueId}/members/${targetDriverId}/remove`, { performerDriverId });
|
|
}
|
|
|
|
/** Update a member's role in league */
|
|
updateMemberRole(leagueId: string, performerDriverId: string, targetDriverId: string, newRole: string): Promise<{ success: boolean }> {
|
|
return this.patch<{ success: boolean }>(`/leagues/${leagueId}/members/${targetDriverId}/role`, { performerDriverId, newRole });
|
|
}
|
|
|
|
/** Get league seasons */
|
|
getSeasons(leagueId: string): Promise<LeagueSeasonSummaryDTO[]> {
|
|
return this.get<LeagueSeasonSummaryDTO[]>(`/leagues/${leagueId}/seasons`);
|
|
}
|
|
|
|
/** Get season sponsorships */
|
|
getSeasonSponsorships(seasonId: string): Promise<{ sponsorships: SponsorshipDetailDTO[] }> {
|
|
return this.get<{ sponsorships: SponsorshipDetailDTO[] }>(`/leagues/seasons/${seasonId}/sponsorships`);
|
|
}
|
|
|
|
/** Get league config */
|
|
getLeagueConfig(leagueId: string): Promise<GetLeagueAdminConfigOutputDTO> {
|
|
return this.get<GetLeagueAdminConfigOutputDTO>(`/leagues/${leagueId}/config`);
|
|
}
|
|
|
|
/** Get league scoring presets */
|
|
getScoringPresets(): Promise<{ presets: LeagueScoringPresetDTO[] }> {
|
|
return this.get<{ presets: LeagueScoringPresetDTO[] }>(`/leagues/scoring-presets`);
|
|
}
|
|
|
|
/** Transfer league ownership */
|
|
transferOwnership(leagueId: string, currentOwnerId: string, newOwnerId: string): Promise<{ success: boolean }> {
|
|
return this.post<{ success: boolean }>(`/leagues/${leagueId}/transfer-ownership`, {
|
|
currentOwnerId,
|
|
newOwnerId,
|
|
});
|
|
}
|
|
|
|
/** Get races for a league */
|
|
getRaces(leagueId: string): Promise<{ races: RaceDTO[] }> {
|
|
return this.get<{ races: RaceDTO[] }>(`/leagues/${leagueId}/races`);
|
|
}
|
|
}
|