fix data flow issues
This commit is contained in:
@@ -1,63 +1,65 @@
|
||||
// Note: No generated DTO available for RaceCard yet
|
||||
interface RaceCardDTO {
|
||||
id: string;
|
||||
title: string;
|
||||
scheduledTime: string;
|
||||
status: string;
|
||||
}
|
||||
import { RaceListItemViewModel } from './RaceListItemViewModel';
|
||||
|
||||
/**
|
||||
* Race card view model
|
||||
* Represents a race card in list views
|
||||
*/
|
||||
export class RaceCardViewModel {
|
||||
id: string;
|
||||
title: string;
|
||||
scheduledTime: string;
|
||||
status: string;
|
||||
|
||||
constructor(dto: RaceCardDTO) {
|
||||
this.id = dto.id;
|
||||
this.title = dto.title;
|
||||
this.scheduledTime = dto.scheduledTime;
|
||||
this.status = dto.status;
|
||||
}
|
||||
|
||||
/** UI-specific: Formatted scheduled time */
|
||||
get formattedScheduledTime(): string {
|
||||
return new Date(this.scheduledTime).toLocaleString();
|
||||
}
|
||||
}
|
||||
|
||||
// Note: No generated DTO available for RacesPage yet
|
||||
// DTO matching the backend RacesPageDataDTO
|
||||
interface RacesPageDTO {
|
||||
upcomingRaces: RaceCardDTO[];
|
||||
completedRaces: RaceCardDTO[];
|
||||
totalCount: number;
|
||||
races: Array<{
|
||||
id: string;
|
||||
track: string;
|
||||
car: string;
|
||||
scheduledAt: string;
|
||||
status: string;
|
||||
leagueId: string;
|
||||
leagueName: string;
|
||||
strengthOfField: number | null;
|
||||
isUpcoming: boolean;
|
||||
isLive: boolean;
|
||||
isPast: boolean;
|
||||
}>;
|
||||
}
|
||||
|
||||
/**
|
||||
* Races page view model
|
||||
* Represents the races page data
|
||||
* Represents the races page data with all races in a single list
|
||||
*/
|
||||
export class RacesPageViewModel {
|
||||
upcomingRaces: RaceCardViewModel[];
|
||||
completedRaces: RaceCardViewModel[];
|
||||
totalCount: number;
|
||||
races: RaceListItemViewModel[];
|
||||
|
||||
constructor(dto: RacesPageDTO) {
|
||||
this.upcomingRaces = dto.upcomingRaces.map(r => new RaceCardViewModel(r));
|
||||
this.completedRaces = dto.completedRaces.map(r => new RaceCardViewModel(r));
|
||||
this.totalCount = dto.totalCount;
|
||||
this.races = dto.races.map(r => new RaceListItemViewModel(r));
|
||||
}
|
||||
|
||||
/** UI-specific: Total upcoming races */
|
||||
get upcomingCount(): number {
|
||||
return this.upcomingRaces.length;
|
||||
/** UI-specific: Total races */
|
||||
get totalCount(): number {
|
||||
return this.races.length;
|
||||
}
|
||||
|
||||
/** UI-specific: Total completed races */
|
||||
get completedCount(): number {
|
||||
return this.completedRaces.length;
|
||||
/** UI-specific: Upcoming races */
|
||||
get upcomingRaces(): RaceListItemViewModel[] {
|
||||
return this.races.filter(r => r.isUpcoming);
|
||||
}
|
||||
|
||||
/** UI-specific: Live races */
|
||||
get liveRaces(): RaceListItemViewModel[] {
|
||||
return this.races.filter(r => r.isLive);
|
||||
}
|
||||
|
||||
/** UI-specific: Past races */
|
||||
get pastRaces(): RaceListItemViewModel[] {
|
||||
return this.races.filter(r => r.isPast);
|
||||
}
|
||||
|
||||
/** UI-specific: Scheduled races */
|
||||
get scheduledRaces(): RaceListItemViewModel[] {
|
||||
return this.races.filter(r => r.status === 'scheduled');
|
||||
}
|
||||
|
||||
/** UI-specific: Running races */
|
||||
get runningRaces(): RaceListItemViewModel[] {
|
||||
return this.races.filter(r => r.status === 'running');
|
||||
}
|
||||
|
||||
/** UI-specific: Completed races */
|
||||
get completedRaces(): RaceListItemViewModel[] {
|
||||
return this.races.filter(r => r.status === 'completed');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user