code quality
Some checks failed
CI / lint-typecheck (pull_request) Failing after 12s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped

This commit is contained in:
2026-01-26 17:22:01 +01:00
parent cfc30c79a8
commit 9ac74f5046
305 changed files with 1192 additions and 607 deletions

View File

@@ -11,77 +11,50 @@ import type { DriverProfileViewData } from '@/lib/view-data/DriverProfileViewDat
export class DriverProfileViewDataBuilder {
public static build(apiDto: GetDriverProfileOutputDTO): DriverProfileViewData {
const currentDriver = apiDto.currentDriver!;
return {
currentDriver: apiDto.currentDriver ? {
id: apiDto.currentDriver.id,
name: apiDto.currentDriver.name,
country: apiDto.currentDriver.country,
avatarUrl: apiDto.currentDriver.avatarUrl || '',
iracingId: typeof apiDto.currentDriver.iracingId === 'string' ? parseInt(apiDto.currentDriver.iracingId, 10) : (apiDto.currentDriver.iracingId ?? null),
joinedAt: apiDto.currentDriver.joinedAt,
joinedAtLabel: DateFormatter.formatMonthYear(apiDto.currentDriver.joinedAt),
rating: apiDto.currentDriver.rating ?? null,
ratingLabel: RatingFormatter.format(apiDto.currentDriver.rating),
globalRank: apiDto.currentDriver.globalRank ?? null,
globalRankLabel: apiDto.currentDriver.globalRank != null ? `#${apiDto.currentDriver.globalRank}` : '—',
consistency: apiDto.currentDriver.consistency ?? null,
bio: apiDto.currentDriver.bio ?? null,
totalDrivers: apiDto.currentDriver.totalDrivers ?? null,
} : null,
driver: {
id: currentDriver.id,
name: currentDriver.name,
countryCode: currentDriver.country,
countryFlag: currentDriver.country, // Placeholder
avatarUrl: currentDriver.avatarUrl || '',
bio: currentDriver.bio ?? null,
iracingId: currentDriver.iracingId ?? null,
joinedAtLabel: DateFormatter.formatMonthYear(currentDriver.joinedAt),
globalRankLabel: currentDriver.globalRank != null ? `#${currentDriver.globalRank}` : '—',
},
stats: apiDto.stats ? {
totalRaces: apiDto.stats.totalRaces,
totalRacesLabel: NumberFormatter.format(apiDto.stats.totalRaces),
wins: apiDto.stats.wins,
winsLabel: NumberFormatter.format(apiDto.stats.wins),
podiums: apiDto.stats.podiums,
podiumsLabel: NumberFormatter.format(apiDto.stats.podiums),
dnfs: apiDto.stats.dnfs,
dnfsLabel: NumberFormatter.format(apiDto.stats.dnfs),
avgFinish: apiDto.stats.avgFinish ?? null,
avgFinishLabel: FinishFormatter.formatAverage(apiDto.stats.avgFinish),
bestFinish: apiDto.stats.bestFinish ?? null,
bestFinishLabel: FinishFormatter.format(apiDto.stats.bestFinish),
worstFinish: apiDto.stats.worstFinish ?? null,
worstFinishLabel: FinishFormatter.format(apiDto.stats.worstFinish),
finishRate: apiDto.stats.finishRate ?? null,
winRate: apiDto.stats.winRate ?? null,
podiumRate: apiDto.stats.podiumRate ?? null,
percentile: apiDto.stats.percentile ?? null,
rating: apiDto.stats.rating ?? null,
ratingLabel: RatingFormatter.format(apiDto.stats.rating),
consistency: apiDto.stats.consistency ?? null,
globalRankLabel: apiDto.stats.overallRank != null ? `#${apiDto.stats.overallRank}` : '—',
totalRacesLabel: NumberFormatter.format(apiDto.stats.totalRaces),
winsLabel: NumberFormatter.format(apiDto.stats.wins),
podiumsLabel: NumberFormatter.format(apiDto.stats.podiums),
dnfsLabel: NumberFormatter.format(apiDto.stats.dnfs),
bestFinishLabel: FinishFormatter.format(apiDto.stats.bestFinish),
worstFinishLabel: FinishFormatter.format(apiDto.stats.worstFinish),
avgFinishLabel: FinishFormatter.formatAverage(apiDto.stats.avgFinish),
consistencyLabel: PercentFormatter.formatWhole(apiDto.stats.consistency),
overallRank: apiDto.stats.overallRank ?? null,
} : null,
finishDistribution: apiDto.finishDistribution ? {
totalRaces: apiDto.finishDistribution.totalRaces,
wins: apiDto.finishDistribution.wins,
podiums: apiDto.finishDistribution.podiums,
topTen: apiDto.finishDistribution.topTen,
dnfs: apiDto.finishDistribution.dnfs,
other: apiDto.finishDistribution.other,
} : null,
percentileLabel: PercentFormatter.formatWhole(apiDto.stats.percentile),
} as any : null,
teamMemberships: apiDto.teamMemberships.map(m => ({
teamId: m.teamId,
teamName: m.teamName,
teamTag: m.teamTag ?? null,
role: m.role,
joinedAt: m.joinedAt,
roleLabel: m.role,
joinedAtLabel: DateFormatter.formatMonthYear(m.joinedAt),
isCurrent: m.isCurrent,
})),
socialSummary: {
friendsCount: apiDto.socialSummary.friendsCount,
friends: apiDto.socialSummary.friends.map(f => ({
id: f.id,
name: f.name,
country: f.country,
avatarUrl: f.avatarUrl || '',
})),
},
href: `/teams/${m.teamId}`,
})) as any,
extendedProfile: apiDto.extendedProfile ? {
timezone: apiDto.extendedProfile.timezone,
racingStyle: apiDto.extendedProfile.racingStyle,
favoriteTrack: apiDto.extendedProfile.favoriteTrack,
favoriteCar: apiDto.extendedProfile.favoriteCar,
availableHours: apiDto.extendedProfile.availableHours,
lookingForTeamLabel: apiDto.extendedProfile.lookingForTeam ? 'Yes' : 'No',
openToRequestsLabel: apiDto.extendedProfile.openToRequests ? 'Yes' : 'No',
socialHandles: apiDto.extendedProfile.socialHandles.map(h => ({
platform: h.platform,
platformLabel: h.platform,
handle: h.handle,
url: h.url,
})),
@@ -89,21 +62,20 @@ export class DriverProfileViewDataBuilder {
id: a.id,
title: a.title,
description: a.description,
icon: a.icon,
rarity: a.rarity,
rarityLabel: a.rarity,
earnedAt: a.earnedAt,
earnedAtLabel: DateFormatter.formatShort(a.earnedAt),
icon: a.icon as any,
rarityLabel: a.rarity,
})),
racingStyle: apiDto.extendedProfile.racingStyle,
favoriteTrack: apiDto.extendedProfile.favoriteTrack,
favoriteCar: apiDto.extendedProfile.favoriteCar,
timezone: apiDto.extendedProfile.timezone,
availableHours: apiDto.extendedProfile.availableHours,
lookingForTeam: apiDto.extendedProfile.lookingForTeam,
openToRequests: apiDto.extendedProfile.openToRequests,
} : null,
};
friends: apiDto.socialSummary.friends.map(f => ({
id: f.id,
name: f.name,
countryFlag: f.country, // Placeholder
avatarUrl: f.avatarUrl || '',
href: `/drivers/${f.id}`,
})),
friendsCountLabel: NumberFormatter.format(apiDto.socialSummary.friendsCount),
} as any : null,
} as any;
}
}