Files
gridpilot.gg/apps/website/lib/view-models/DashboardOverviewViewModel.ts

181 lines
3.4 KiB
TypeScript

import { DashboardOverviewDto, DriverDto, RaceDto, LeagueStandingDto, FeedItemDto, FriendDto } from '../api/dashboard/DashboardApiClient';
export class DriverViewModel {
constructor(private readonly dto: DriverDto) {}
get id(): string {
return this.dto.id;
}
get name(): string {
return this.dto.name;
}
get avatarUrl(): string {
return this.dto.avatarUrl;
}
get country(): string {
return this.dto.country;
}
get totalRaces(): number {
return this.dto.totalRaces;
}
get wins(): number {
return this.dto.wins;
}
get podiums(): number {
return this.dto.podiums;
}
get rating(): number {
return this.dto.rating;
}
get globalRank(): number {
return this.dto.globalRank;
}
get consistency(): number {
return this.dto.consistency;
}
}
export class RaceViewModel {
constructor(private readonly dto: RaceDto) {}
get id(): string {
return this.dto.id;
}
get track(): string {
return this.dto.track;
}
get car(): string {
return this.dto.car;
}
get scheduledAt(): Date {
return new Date(this.dto.scheduledAt);
}
get isMyLeague(): boolean {
return this.dto.isMyLeague;
}
get leagueName(): string | undefined {
return this.dto.leagueName;
}
}
export class LeagueStandingViewModel {
constructor(private readonly dto: LeagueStandingDto) {}
get leagueId(): string {
return this.dto.leagueId;
}
get leagueName(): string {
return this.dto.leagueName;
}
get position(): number {
return this.dto.position;
}
get points(): number {
return this.dto.points;
}
get totalDrivers(): number {
return this.dto.totalDrivers;
}
}
export class DashboardFeedItemSummaryViewModel {
constructor(private readonly dto: FeedItemDto) {}
get id(): string {
return this.dto.id;
}
get type(): string {
return this.dto.type;
}
get headline(): string {
return this.dto.headline;
}
get body(): string | null {
return this.dto.body;
}
get timestamp(): Date {
return new Date(this.dto.timestamp);
}
get ctaHref(): string | undefined {
return this.dto.ctaHref;
}
get ctaLabel(): string | undefined {
return this.dto.ctaLabel;
}
}
export class FriendViewModel {
constructor(private readonly dto: FriendDto) {}
get id(): string {
return this.dto.id;
}
get name(): string {
return this.dto.name;
}
get avatarUrl(): string {
return this.dto.avatarUrl;
}
get country(): string {
return this.dto.country;
}
}
export class DashboardOverviewViewModel {
constructor(private readonly dto: DashboardOverviewDto) {}
get currentDriver(): DriverViewModel {
return new DriverViewModel(this.dto.currentDriver);
}
get nextRace(): RaceViewModel | null {
return this.dto.nextRace ? new RaceViewModel(this.dto.nextRace) : null;
}
get upcomingRaces(): RaceViewModel[] {
return this.dto.upcomingRaces.map(dto => new RaceViewModel(dto));
}
get leagueStandings(): LeagueStandingViewModel[] {
return this.dto.leagueStandings.map(dto => new LeagueStandingViewModel(dto));
}
get feedItems(): DashboardFeedItemSummaryViewModel[] {
return this.dto.feedItems.map(dto => new DashboardFeedItemSummaryViewModel(dto));
}
get friends(): FriendViewModel[] {
return this.dto.friends.map(dto => new FriendViewModel(dto));
}
get activeLeaguesCount(): number {
return this.dto.activeLeaguesCount;
}
}