view models
This commit is contained in:
@@ -1,11 +1,14 @@
|
||||
import type { LeaguesApiClient } from '../../api/leagues/LeaguesApiClient';
|
||||
import { LeagueSummaryViewModel, LeagueStandingsViewModel } from '../../view-models';
|
||||
import type { CreateLeagueInputDTO, CreateLeagueOutputDTO, LeagueWithCapacityDTO } from '../../types/generated';
|
||||
import { LeaguesApiClient } from "@/lib/api/leagues/LeaguesApiClient";
|
||||
import { CreateLeagueInputDTO } from "@/lib/types/generated/CreateLeagueInputDTO";
|
||||
import { LeagueWithCapacityDTO } from "@/lib/types/generated/LeagueWithCapacityDTO";
|
||||
import { CreateLeagueViewModel } from "@/lib/view-models/CreateLeagueViewModel";
|
||||
import { LeagueMembershipsViewModel } from "@/lib/view-models/LeagueMembershipsViewModel";
|
||||
import { LeagueScheduleViewModel } from "@/lib/view-models/LeagueScheduleViewModel";
|
||||
import { LeagueStandingsViewModel } from "@/lib/view-models/LeagueStandingsViewModel";
|
||||
import { LeagueStatsViewModel } from "@/lib/view-models/LeagueStatsViewModel";
|
||||
import { LeagueSummaryViewModel } from "@/lib/view-models/LeagueSummaryViewModel";
|
||||
import { RemoveMemberViewModel } from "@/lib/view-models/RemoveMemberViewModel";
|
||||
|
||||
// TODO: Move these types to apps/website/lib/types/generated when available
|
||||
type LeagueStatsDto = { totalLeagues: number };
|
||||
type LeagueScheduleDto = { races: Array<unknown> };
|
||||
type LeagueMembershipsDto = { memberships: Array<unknown> };
|
||||
|
||||
/**
|
||||
* League Service
|
||||
@@ -43,35 +46,40 @@ export class LeagueService {
|
||||
/**
|
||||
* Get league statistics
|
||||
*/
|
||||
async getLeagueStats(): Promise<LeagueStatsDto> {
|
||||
return await this.apiClient.getTotal();
|
||||
async getLeagueStats(): Promise<LeagueStatsViewModel> {
|
||||
const dto = await this.apiClient.getTotal();
|
||||
return new LeagueStatsViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get league schedule
|
||||
*/
|
||||
async getLeagueSchedule(leagueId: string): Promise<LeagueScheduleDto> {
|
||||
return await this.apiClient.getSchedule(leagueId);
|
||||
async getLeagueSchedule(leagueId: string): Promise<LeagueScheduleViewModel> {
|
||||
const dto = await this.apiClient.getSchedule(leagueId);
|
||||
return new LeagueScheduleViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Get league memberships
|
||||
*/
|
||||
async getLeagueMemberships(leagueId: string): Promise<LeagueMembershipsDto> {
|
||||
return await this.apiClient.getMemberships(leagueId);
|
||||
async getLeagueMemberships(leagueId: string, currentUserId: string): Promise<LeagueMembershipsViewModel> {
|
||||
const dto = await this.apiClient.getMemberships(leagueId);
|
||||
return new LeagueMembershipsViewModel(dto, currentUserId);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new league
|
||||
*/
|
||||
async createLeague(input: CreateLeagueInputDTO): Promise<CreateLeagueOutputDTO> {
|
||||
return await this.apiClient.create(input);
|
||||
async createLeague(input: CreateLeagueInputDTO): Promise<CreateLeagueViewModel> {
|
||||
const dto = await this.apiClient.create(input);
|
||||
return new CreateLeagueViewModel(dto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove a member from league
|
||||
*/
|
||||
async removeMember(leagueId: string, performerDriverId: string, targetDriverId: string): Promise<{ success: boolean }> {
|
||||
return await this.apiClient.removeMember(leagueId, performerDriverId, targetDriverId);
|
||||
async removeMember(leagueId: string, performerDriverId: string, targetDriverId: string): Promise<RemoveMemberViewModel> {
|
||||
const dto = await this.apiClient.removeMember(leagueId, performerDriverId, targetDriverId);
|
||||
return new RemoveMemberViewModel(dto);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user