api client refactor
This commit is contained in:
28
apps/website/lib/services/leagues/LeagueService.ts
Normal file
28
apps/website/lib/services/leagues/LeagueService.ts
Normal file
@@ -0,0 +1,28 @@
|
||||
import { api as api } from '../../api';
|
||||
import { presentLeagueSummaries, presentLeagueStandings } from '../../presenters';
|
||||
import { LeagueSummaryViewModel, LeagueStandingsViewModel } from '../../view-models';
|
||||
|
||||
export async function getAllLeagues(): Promise<LeagueSummaryViewModel[]> {
|
||||
const dto = await api.leagues.getAllWithCapacity();
|
||||
return presentLeagueSummaries(dto.leagues);
|
||||
}
|
||||
|
||||
export async function getLeagueStandings(leagueId: string, currentUserId?: string): Promise<LeagueStandingsViewModel> {
|
||||
const dto = await api.leagues.getStandings(leagueId);
|
||||
// TODO: include drivers and memberships in dto
|
||||
const dtoWithExtras = {
|
||||
...dto,
|
||||
drivers: [], // TODO: fetch drivers
|
||||
memberships: [], // TODO: fetch memberships
|
||||
};
|
||||
return presentLeagueStandings(dtoWithExtras, currentUserId || '');
|
||||
}
|
||||
|
||||
export async function createLeague(input: any): Promise<any> {
|
||||
return await api.leagues.create(input);
|
||||
}
|
||||
|
||||
export async function getLeagueAdminView(leagueId: string): Promise<any> {
|
||||
// TODO: implement
|
||||
return {};
|
||||
}
|
||||
Reference in New Issue
Block a user