view data fixes
This commit is contained in:
@@ -1,23 +1,55 @@
|
||||
import type { GetDriverOutputDTO } from '@/lib/types/generated/GetDriverOutputDTO';
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
import type { DriverSummaryData } from "../view-data/LeagueDetailViewData";
|
||||
import { NumberDisplay } from "../display-objects/NumberDisplay";
|
||||
import { RatingDisplay } from "../display-objects/RatingDisplay";
|
||||
|
||||
/**
|
||||
* View Model for driver summary with rating and rank
|
||||
* Transform from DTO to ViewModel with UI fields
|
||||
*
|
||||
* Client-only UI helper built from ViewData.
|
||||
*/
|
||||
import { ViewModel } from "../contracts/view-models/ViewModel";
|
||||
|
||||
export class DriverSummaryViewModel extends ViewModel {
|
||||
driver: GetDriverOutputDTO;
|
||||
rating: number | null;
|
||||
rank: number | null;
|
||||
constructor(private readonly viewData: DriverSummaryData) {
|
||||
super();
|
||||
}
|
||||
|
||||
constructor(dto: {
|
||||
driver: GetDriverOutputDTO;
|
||||
rating?: number | null;
|
||||
rank?: number | null;
|
||||
}) {
|
||||
this.driver = dto.driver;
|
||||
this.rating = dto.rating ?? null;
|
||||
this.rank = dto.rank ?? null;
|
||||
get id(): string {
|
||||
return this.viewData.driverId;
|
||||
}
|
||||
|
||||
get name(): string {
|
||||
return this.viewData.driverName;
|
||||
}
|
||||
|
||||
get avatarUrl(): string | null {
|
||||
return this.viewData.avatarUrl;
|
||||
}
|
||||
|
||||
get rating(): number | null {
|
||||
return this.viewData.rating;
|
||||
}
|
||||
|
||||
get ratingLabel(): string {
|
||||
return RatingDisplay.format(this.rating);
|
||||
}
|
||||
|
||||
get rank(): number | null {
|
||||
return this.viewData.rank;
|
||||
}
|
||||
|
||||
get rankLabel(): string {
|
||||
return this.rank === null ? '—' : NumberDisplay.format(this.rank);
|
||||
}
|
||||
|
||||
get roleBadgeText(): string {
|
||||
return this.viewData.roleBadgeText;
|
||||
}
|
||||
|
||||
get roleBadgeClasses(): string {
|
||||
return this.viewData.roleBadgeClasses;
|
||||
}
|
||||
|
||||
get profileUrl(): string {
|
||||
return this.viewData.profileUrl;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user