website cleanup
This commit is contained in:
@@ -1,7 +1,12 @@
|
||||
import { DashboardOverviewDto, DriverDto, RaceDto, LeagueStandingDto, FeedItemDto, FriendDto } from '../api/dashboard/DashboardApiClient';
|
||||
import type { DashboardOverviewDTO } from '@/lib/types/generated/DashboardOverviewDTO';
|
||||
import type { DashboardDriverSummaryDTO } from '@/lib/types/generated/DashboardDriverSummaryDTO';
|
||||
import type { DashboardRaceSummaryDTO } from '@/lib/types/generated/DashboardRaceSummaryDTO';
|
||||
import type { DashboardLeagueStandingSummaryDTO } from '@/lib/types/generated/DashboardLeagueStandingSummaryDTO';
|
||||
import type { DashboardFeedItemSummaryDTO } from '@/lib/types/generated/DashboardFeedItemSummaryDTO';
|
||||
import type { DashboardFriendSummaryDTO } from '@/lib/types/generated/DashboardFriendSummaryDTO';
|
||||
|
||||
export class DriverViewModel {
|
||||
constructor(private readonly dto: DriverDto) {}
|
||||
export class DashboardDriverSummaryViewModel {
|
||||
constructor(private readonly dto: DashboardDriverSummaryDTO) {}
|
||||
|
||||
get id(): string {
|
||||
return this.dto.id;
|
||||
@@ -32,25 +37,33 @@ export class DriverViewModel {
|
||||
}
|
||||
|
||||
get rating(): number {
|
||||
return this.dto.rating;
|
||||
return this.dto.rating ?? 0;
|
||||
}
|
||||
|
||||
get globalRank(): number {
|
||||
return this.dto.globalRank;
|
||||
return this.dto.globalRank ?? 0;
|
||||
}
|
||||
|
||||
get consistency(): number {
|
||||
return this.dto.consistency;
|
||||
return this.dto.consistency ?? 0;
|
||||
}
|
||||
}
|
||||
|
||||
export class RaceViewModel {
|
||||
constructor(private readonly dto: RaceDto) {}
|
||||
export class DashboardRaceSummaryViewModel {
|
||||
constructor(private readonly dto: DashboardRaceSummaryDTO) {}
|
||||
|
||||
get id(): string {
|
||||
return this.dto.id;
|
||||
}
|
||||
|
||||
get leagueId(): string {
|
||||
return this.dto.leagueId;
|
||||
}
|
||||
|
||||
get leagueName(): string {
|
||||
return this.dto.leagueName;
|
||||
}
|
||||
|
||||
get track(): string {
|
||||
return this.dto.track;
|
||||
}
|
||||
@@ -63,17 +76,17 @@ export class RaceViewModel {
|
||||
return new Date(this.dto.scheduledAt);
|
||||
}
|
||||
|
||||
get status(): string {
|
||||
return this.dto.status;
|
||||
}
|
||||
|
||||
get isMyLeague(): boolean {
|
||||
return this.dto.isMyLeague;
|
||||
}
|
||||
|
||||
get leagueName(): string | undefined {
|
||||
return this.dto.leagueName;
|
||||
}
|
||||
}
|
||||
|
||||
export class LeagueStandingViewModel {
|
||||
constructor(private readonly dto: LeagueStandingDto) {}
|
||||
export class DashboardLeagueStandingSummaryViewModel {
|
||||
constructor(private readonly dto: DashboardLeagueStandingSummaryDTO) {}
|
||||
|
||||
get leagueId(): string {
|
||||
return this.dto.leagueId;
|
||||
@@ -97,7 +110,7 @@ export class LeagueStandingViewModel {
|
||||
}
|
||||
|
||||
export class DashboardFeedItemSummaryViewModel {
|
||||
constructor(private readonly dto: FeedItemDto) {}
|
||||
constructor(private readonly dto: DashboardFeedItemSummaryDTO) {}
|
||||
|
||||
get id(): string {
|
||||
return this.dto.id;
|
||||
@@ -111,7 +124,7 @@ export class DashboardFeedItemSummaryViewModel {
|
||||
return this.dto.headline;
|
||||
}
|
||||
|
||||
get body(): string | null {
|
||||
get body(): string | undefined {
|
||||
return this.dto.body;
|
||||
}
|
||||
|
||||
@@ -128,8 +141,8 @@ export class DashboardFeedItemSummaryViewModel {
|
||||
}
|
||||
}
|
||||
|
||||
export class FriendViewModel {
|
||||
constructor(private readonly dto: FriendDto) {}
|
||||
export class DashboardFriendSummaryViewModel {
|
||||
constructor(private readonly dto: DashboardFriendSummaryDTO) {}
|
||||
|
||||
get id(): string {
|
||||
return this.dto.id;
|
||||
@@ -149,33 +162,42 @@ export class FriendViewModel {
|
||||
}
|
||||
|
||||
export class DashboardOverviewViewModel {
|
||||
constructor(private readonly dto: DashboardOverviewDto) {}
|
||||
constructor(private readonly dto: DashboardOverviewDTO) {}
|
||||
|
||||
get currentDriver(): DriverViewModel {
|
||||
return new DriverViewModel(this.dto.currentDriver);
|
||||
get currentDriver(): DashboardDriverSummaryViewModel {
|
||||
// DTO uses optional property; enforce a consistent object for the UI
|
||||
return new DashboardDriverSummaryViewModel(this.dto.currentDriver ?? {
|
||||
id: '',
|
||||
name: '',
|
||||
country: '',
|
||||
avatarUrl: '',
|
||||
totalRaces: 0,
|
||||
wins: 0,
|
||||
podiums: 0,
|
||||
});
|
||||
}
|
||||
|
||||
get nextRace(): RaceViewModel | null {
|
||||
return this.dto.nextRace ? new RaceViewModel(this.dto.nextRace) : null;
|
||||
get nextRace(): DashboardRaceSummaryViewModel | null {
|
||||
return this.dto.nextRace ? new DashboardRaceSummaryViewModel(this.dto.nextRace) : null;
|
||||
}
|
||||
|
||||
get upcomingRaces(): RaceViewModel[] {
|
||||
return this.dto.upcomingRaces.map(dto => new RaceViewModel(dto));
|
||||
get upcomingRaces(): DashboardRaceSummaryViewModel[] {
|
||||
return this.dto.upcomingRaces.map((r) => new DashboardRaceSummaryViewModel(r));
|
||||
}
|
||||
|
||||
get leagueStandings(): LeagueStandingViewModel[] {
|
||||
return this.dto.leagueStandings.map(dto => new LeagueStandingViewModel(dto));
|
||||
get leagueStandings(): DashboardLeagueStandingSummaryViewModel[] {
|
||||
return this.dto.leagueStandingsSummaries.map((s) => new DashboardLeagueStandingSummaryViewModel(s));
|
||||
}
|
||||
|
||||
get feedItems(): DashboardFeedItemSummaryViewModel[] {
|
||||
return this.dto.feedItems.map(dto => new DashboardFeedItemSummaryViewModel(dto));
|
||||
return this.dto.feedSummary.items.map((i) => new DashboardFeedItemSummaryViewModel(i));
|
||||
}
|
||||
|
||||
get friends(): FriendViewModel[] {
|
||||
return this.dto.friends.map(dto => new FriendViewModel(dto));
|
||||
get friends(): DashboardFriendSummaryViewModel[] {
|
||||
return this.dto.friends.map((f) => new DashboardFriendSummaryViewModel(f));
|
||||
}
|
||||
|
||||
get activeLeaguesCount(): number {
|
||||
return this.dto.activeLeaguesCount;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user