92 lines
3.2 KiB
TypeScript
92 lines
3.2 KiB
TypeScript
import { BaseApiClient } from '../base/BaseApiClient';
|
|
import type {
|
|
AllLeaguesWithCapacityDto,
|
|
LeagueStatsDto,
|
|
LeagueStandingsDto,
|
|
LeagueScheduleDto,
|
|
LeagueMembershipsDto,
|
|
CreateLeagueInputDto,
|
|
CreateLeagueOutputDto,
|
|
SponsorshipDetailDTO,
|
|
RaceDTO,
|
|
} from '../../dtos';
|
|
|
|
/**
|
|
* 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 total number of leagues */
|
|
getTotal(): Promise<LeagueStatsDto> {
|
|
return this.get<LeagueStatsDto>('/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<{ seasons: Array<{ id: string; status: string }> }> {
|
|
return this.get<{ seasons: Array<{ id: string; status: string }> }>(`/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<{ config: any }> {
|
|
return this.get<{ config: any }>(`/leagues/${leagueId}/config`);
|
|
}
|
|
|
|
/** Get league scoring presets */
|
|
getScoringPresets(): Promise<{ presets: any[] }> {
|
|
return this.get<{ presets: any[] }>(`/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`);
|
|
}
|
|
} |