19 lines
954 B
TypeScript
19 lines
954 B
TypeScript
import { LeagueStandingsDto, StandingEntryDto, DriverDto, LeagueMembership } from '../dtos';
|
|
import { StandingEntryViewModel } from './StandingEntryViewModel';
|
|
|
|
export class LeagueStandingsViewModel implements LeagueStandingsDto {
|
|
standings: StandingEntryViewModel[];
|
|
drivers: DriverDto[];
|
|
memberships: LeagueMembership[];
|
|
|
|
constructor(dto: LeagueStandingsDto & { standings: StandingEntryDto[] }, currentUserId: string, previousStandings?: StandingEntryDto[]) {
|
|
const leaderPoints = dto.standings[0]?.points || 0;
|
|
this.standings = dto.standings.map((entry, index) => {
|
|
const nextPoints = dto.standings[index + 1]?.points || entry.points;
|
|
const previousPosition = previousStandings?.find(p => p.driverId === entry.driverId)?.position;
|
|
return new StandingEntryViewModel(entry, leaderPoints, nextPoints, currentUserId, previousPosition);
|
|
});
|
|
this.drivers = dto.drivers;
|
|
this.memberships = dto.memberships;
|
|
}
|
|
} |