do to formatters

This commit is contained in:
2026-01-24 01:07:43 +01:00
parent ae59df61eb
commit 891b3cf0ee
140 changed files with 656 additions and 1159 deletions

View File

@@ -1,14 +1,14 @@
'use client';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { DashboardConsistencyFormatter } from '@/lib/formatters/DashboardConsistencyFormatter';
import { DashboardCountFormatter } from '@/lib/formatters/DashboardCountFormatter';
import { DashboardDateFormatter } from '@/lib/formatters/DashboardDateFormatter';
import { DashboardLeaguePositionFormatter } from '@/lib/formatters/DashboardLeaguePositionFormatter';
import { DashboardRankFormatter } from '@/lib/formatters/DashboardRankFormatter';
import { RatingFormatter } from '@/lib/formatters/RatingFormatter';
import type { DashboardOverviewDTO } from '@/lib/types/generated/DashboardOverviewDTO';
import type { DashboardViewData } from '@/lib/view-data/DashboardViewData';
import { DashboardDateDisplay } from '@/lib/display-objects/DashboardDateDisplay';
import { RatingDisplay } from '@/lib/display-objects/RatingDisplay';
import { DashboardRankDisplay } from '@/lib/display-objects/DashboardRankDisplay';
import { DashboardConsistencyDisplay } from '@/lib/display-objects/DashboardConsistencyDisplay';
import { DashboardCountDisplay } from '@/lib/display-objects/DashboardCountDisplay';
import { DashboardLeaguePositionDisplay } from '@/lib/display-objects/DashboardLeaguePositionDisplay';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
export class DashboardViewDataBuilder {
public static build(apiDto: DashboardOverviewDTO): DashboardViewData {
@@ -17,21 +17,21 @@ export class DashboardViewDataBuilder {
name: apiDto.currentDriver?.name || '',
avatarUrl: apiDto.currentDriver?.avatarUrl || '',
country: apiDto.currentDriver?.country || '',
rating: apiDto.currentDriver ? RatingDisplay.format(apiDto.currentDriver.rating ?? 0) : '0.0',
rank: apiDto.currentDriver ? DashboardRankDisplay.format(apiDto.currentDriver.globalRank ?? 0) : '0',
totalRaces: apiDto.currentDriver ? DashboardCountDisplay.format(apiDto.currentDriver.totalRaces ?? 0) : '0',
wins: apiDto.currentDriver ? DashboardCountDisplay.format(apiDto.currentDriver.wins ?? 0) : '0',
podiums: apiDto.currentDriver ? DashboardCountDisplay.format(apiDto.currentDriver.podiums ?? 0) : '0',
consistency: apiDto.currentDriver ? DashboardConsistencyDisplay.format(apiDto.currentDriver.consistency ?? 0) : '0%',
rating: apiDto.currentDriver ? RatingFormatter.format(apiDto.currentDriver.rating ?? 0) : '0.0',
rank: apiDto.currentDriver ? DashboardRankFormatter.format(apiDto.currentDriver.globalRank ?? 0) : '0',
totalRaces: apiDto.currentDriver ? DashboardCountFormatter.format(apiDto.currentDriver.totalRaces ?? 0) : '0',
wins: apiDto.currentDriver ? DashboardCountFormatter.format(apiDto.currentDriver.wins ?? 0) : '0',
podiums: apiDto.currentDriver ? DashboardCountFormatter.format(apiDto.currentDriver.podiums ?? 0) : '0',
consistency: apiDto.currentDriver ? DashboardConsistencyFormatter.format(apiDto.currentDriver.consistency ?? 0) : '0%',
},
nextRace: apiDto.nextRace ? DashboardViewDataBuilder.buildNextRace(apiDto.nextRace) : null,
upcomingRaces: apiDto.upcomingRaces.map((race) => DashboardViewDataBuilder.buildRace(race)),
leagueStandings: apiDto.leagueStandingsSummaries.map((standing) => ({
leagueId: standing.leagueId,
leagueName: standing.leagueName,
position: DashboardLeaguePositionDisplay.format(standing.position),
points: DashboardCountDisplay.format(standing.points),
totalDrivers: DashboardCountDisplay.format(standing.totalDrivers),
position: DashboardLeaguePositionFormatter.format(standing.position),
points: DashboardCountFormatter.format(standing.points),
totalDrivers: DashboardCountFormatter.format(standing.totalDrivers),
})),
feedItems: apiDto.feedSummary.items.map((item) => ({
id: item.id,
@@ -39,7 +39,7 @@ export class DashboardViewDataBuilder {
headline: item.headline,
body: item.body ?? undefined,
timestamp: item.timestamp,
formattedTime: DashboardDateDisplay.format(new Date(item.timestamp)).relative,
formattedTime: DashboardDateFormatter.format(new Date(item.timestamp)).relative,
ctaHref: item.ctaHref ?? undefined,
ctaLabel: item.ctaLabel ?? undefined,
})),
@@ -49,8 +49,8 @@ export class DashboardViewDataBuilder {
avatarUrl: friend.avatarUrl || '',
country: friend.country,
})),
activeLeaguesCount: DashboardCountDisplay.format(apiDto.activeLeaguesCount),
friendCount: DashboardCountDisplay.format(apiDto.friends.length),
activeLeaguesCount: DashboardCountFormatter.format(apiDto.activeLeaguesCount),
friendCount: DashboardCountFormatter.format(apiDto.friends.length),
hasUpcomingRaces: apiDto.upcomingRaces.length > 0,
hasLeagueStandings: apiDto.leagueStandingsSummaries.length > 0,
hasFeedItems: apiDto.feedSummary.items.length > 0,
@@ -59,7 +59,7 @@ export class DashboardViewDataBuilder {
}
private static buildNextRace(race: NonNullable<DashboardOverviewDTO['nextRace']>) {
const dateInfo = DashboardDateDisplay.format(new Date(race.scheduledAt));
const dateInfo = DashboardDateFormatter.format(new Date(race.scheduledAt));
return {
id: race.id,
track: race.track,
@@ -73,7 +73,7 @@ export class DashboardViewDataBuilder {
}
private static buildRace(race: DashboardOverviewDTO['upcomingRaces'][number]) {
const dateInfo = DashboardDateDisplay.format(new Date(race.scheduledAt));
const dateInfo = DashboardDateFormatter.format(new Date(race.scheduledAt));
return {
id: race.id,
track: race.track,

View File

@@ -1,13 +1,13 @@
'use client';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { DateFormatter } from '@/lib/formatters/DateFormatter';
import { FinishFormatter } from '@/lib/formatters/FinishFormatter';
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
import { PercentFormatter } from '@/lib/formatters/PercentFormatter';
import { RatingFormatter } from '@/lib/formatters/RatingFormatter';
import type { GetDriverProfileOutputDTO } from '@/lib/types/generated/GetDriverProfileOutputDTO';
import type { DriverProfileViewData } from '@/lib/view-data/DriverProfileViewData';
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
import { RatingDisplay } from '@/lib/display-objects/RatingDisplay';
import { NumberDisplay } from '@/lib/display-objects/NumberDisplay';
import { FinishDisplay } from '@/lib/display-objects/FinishDisplay';
import { PercentDisplay } from '@/lib/display-objects/PercentDisplay';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
export class DriverProfileViewDataBuilder {
public static build(apiDto: GetDriverProfileOutputDTO): DriverProfileViewData {
@@ -19,9 +19,9 @@ export class DriverProfileViewDataBuilder {
avatarUrl: apiDto.currentDriver.avatarUrl || '',
iracingId: typeof apiDto.currentDriver.iracingId === 'string' ? parseInt(apiDto.currentDriver.iracingId, 10) : (apiDto.currentDriver.iracingId ?? null),
joinedAt: apiDto.currentDriver.joinedAt,
joinedAtLabel: DateDisplay.formatMonthYear(apiDto.currentDriver.joinedAt),
joinedAtLabel: DateFormatter.formatMonthYear(apiDto.currentDriver.joinedAt),
rating: apiDto.currentDriver.rating ?? null,
ratingLabel: RatingDisplay.format(apiDto.currentDriver.rating),
ratingLabel: RatingFormatter.format(apiDto.currentDriver.rating),
globalRank: apiDto.currentDriver.globalRank ?? null,
globalRankLabel: apiDto.currentDriver.globalRank != null ? `#${apiDto.currentDriver.globalRank}` : '—',
consistency: apiDto.currentDriver.consistency ?? null,
@@ -30,27 +30,27 @@ export class DriverProfileViewDataBuilder {
} : null,
stats: apiDto.stats ? {
totalRaces: apiDto.stats.totalRaces,
totalRacesLabel: NumberDisplay.format(apiDto.stats.totalRaces),
totalRacesLabel: NumberFormatter.format(apiDto.stats.totalRaces),
wins: apiDto.stats.wins,
winsLabel: NumberDisplay.format(apiDto.stats.wins),
winsLabel: NumberFormatter.format(apiDto.stats.wins),
podiums: apiDto.stats.podiums,
podiumsLabel: NumberDisplay.format(apiDto.stats.podiums),
podiumsLabel: NumberFormatter.format(apiDto.stats.podiums),
dnfs: apiDto.stats.dnfs,
dnfsLabel: NumberDisplay.format(apiDto.stats.dnfs),
dnfsLabel: NumberFormatter.format(apiDto.stats.dnfs),
avgFinish: apiDto.stats.avgFinish ?? null,
avgFinishLabel: FinishDisplay.formatAverage(apiDto.stats.avgFinish),
avgFinishLabel: FinishFormatter.formatAverage(apiDto.stats.avgFinish),
bestFinish: apiDto.stats.bestFinish ?? null,
bestFinishLabel: FinishDisplay.format(apiDto.stats.bestFinish),
bestFinishLabel: FinishFormatter.format(apiDto.stats.bestFinish),
worstFinish: apiDto.stats.worstFinish ?? null,
worstFinishLabel: FinishDisplay.format(apiDto.stats.worstFinish),
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: RatingDisplay.format(apiDto.stats.rating),
ratingLabel: RatingFormatter.format(apiDto.stats.rating),
consistency: apiDto.stats.consistency ?? null,
consistencyLabel: PercentDisplay.formatWhole(apiDto.stats.consistency),
consistencyLabel: PercentFormatter.formatWhole(apiDto.stats.consistency),
overallRank: apiDto.stats.overallRank ?? null,
} : null,
finishDistribution: apiDto.finishDistribution ? {
@@ -67,7 +67,7 @@ export class DriverProfileViewDataBuilder {
teamTag: m.teamTag ?? null,
role: m.role,
joinedAt: m.joinedAt,
joinedAtLabel: DateDisplay.formatMonthYear(m.joinedAt),
joinedAtLabel: DateFormatter.formatMonthYear(m.joinedAt),
isCurrent: m.isCurrent,
})),
socialSummary: {
@@ -93,7 +93,7 @@ export class DriverProfileViewDataBuilder {
rarity: a.rarity,
rarityLabel: a.rarity,
earnedAt: a.earnedAt,
earnedAtLabel: DateDisplay.formatShort(a.earnedAt),
earnedAtLabel: DateFormatter.formatShort(a.earnedAt),
})),
racingStyle: apiDto.extendedProfile.racingStyle,
favoriteTrack: apiDto.extendedProfile.favoriteTrack,

View File

@@ -1,10 +1,10 @@
'use client';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { MedalFormatter } from '@/lib/formatters/MedalFormatter';
import { WinRateFormatter } from '@/lib/formatters/WinRateFormatter';
import type { DriverLeaderboardItemDTO } from '@/lib/types/generated/DriverLeaderboardItemDTO';
import type { DriverRankingsViewData } from '@/lib/view-data/DriverRankingsViewData';
import { WinRateDisplay } from '@/lib/display-objects/WinRateDisplay';
import { MedalDisplay } from '@/lib/display-objects/MedalDisplay';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
export class DriverRankingsViewDataBuilder {
public static build(apiDto: DriverLeaderboardItemDTO[]): DriverRankingsViewData {
@@ -31,9 +31,9 @@ export class DriverRankingsViewDataBuilder {
podiums: driver.podiums,
rank: driver.rank,
avatarUrl: driver.avatarUrl || '',
winRate: WinRateDisplay.calculate(driver.racesCompleted, driver.wins),
medalBg: MedalDisplay.getBg(driver.rank),
medalColor: MedalDisplay.getColor(driver.rank),
winRate: WinRateFormatter.calculate(driver.racesCompleted, driver.wins),
medalBg: MedalFormatter.getBg(driver.rank),
medalColor: MedalFormatter.getColor(driver.rank),
})),
podium: apiDto.slice(0, 3).map((driver, index) => {
const positions = [2, 1, 3]; // Display order: 2nd, 1st, 3rd

View File

@@ -1,10 +1,10 @@
'use client';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
import { RatingFormatter } from '@/lib/formatters/RatingFormatter';
import type { DriversLeaderboardDTO } from '@/lib/types/generated/DriversLeaderboardDTO';
import type { DriversViewData } from '@/lib/view-data/DriversViewData';
import { RatingDisplay } from '@/lib/display-objects/RatingDisplay';
import { NumberDisplay } from '@/lib/display-objects/NumberDisplay';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
export class DriversViewDataBuilder {
public static build(apiDto: DriversLeaderboardDTO): DriversViewData {
@@ -13,7 +13,7 @@ export class DriversViewDataBuilder {
id: driver.id,
name: driver.name,
rating: driver.rating,
ratingLabel: RatingDisplay.format(driver.rating),
ratingLabel: RatingFormatter.format(driver.rating),
skillLevel: driver.skillLevel,
category: driver.category ?? undefined,
nationality: driver.nationality,
@@ -25,12 +25,12 @@ export class DriversViewDataBuilder {
avatarUrl: driver.avatarUrl ?? undefined,
})),
totalRaces: apiDto.totalRaces,
totalRacesLabel: NumberDisplay.format(apiDto.totalRaces),
totalRacesLabel: NumberFormatter.format(apiDto.totalRaces),
totalWins: apiDto.totalWins,
totalWinsLabel: NumberDisplay.format(apiDto.totalWins),
totalWinsLabel: NumberFormatter.format(apiDto.totalWins),
activeCount: apiDto.activeCount,
activeCountLabel: NumberDisplay.format(apiDto.activeCount),
totalDriversLabel: NumberDisplay.format(apiDto.drivers.length),
activeCountLabel: NumberFormatter.format(apiDto.activeCount),
totalDriversLabel: NumberFormatter.format(apiDto.drivers.length),
};
}
}

View File

@@ -1,12 +1,12 @@
'use client';
import type { HealthDTO } from '@/lib/types/generated/HealthDTO';
import type { HealthViewData, HealthStatus, HealthMetrics, HealthComponent, HealthAlert } from '@/lib/view-data/HealthViewData';
import { HealthStatusDisplay } from '@/lib/display-objects/HealthStatusDisplay';
import { HealthMetricDisplay } from '@/lib/display-objects/HealthMetricDisplay';
import { HealthComponentDisplay } from '@/lib/display-objects/HealthComponentDisplay';
import { HealthAlertDisplay } from '@/lib/display-objects/HealthAlertDisplay';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { HealthAlertFormatter } from '@/lib/formatters/HealthAlertFormatter';
import { HealthComponentFormatter } from '@/lib/formatters/HealthComponentFormatter';
import { HealthMetricFormatter } from '@/lib/formatters/HealthMetricFormatter';
import { HealthStatusFormatter } from '@/lib/formatters/HealthStatusFormatter';
import type { HealthDTO } from '@/lib/types/generated/HealthDTO';
import type { HealthAlert, HealthComponent, HealthMetrics, HealthStatus, HealthViewData } from '@/lib/view-data/HealthViewData';
export class HealthViewDataBuilder {
public static build(apiDto: HealthDTO): HealthViewData {
@@ -17,37 +17,37 @@ export class HealthViewDataBuilder {
const overallStatus: HealthStatus = {
status: apiDto.status,
timestamp: apiDto.timestamp,
formattedTimestamp: HealthStatusDisplay.formatTimestamp(apiDto.timestamp),
relativeTime: HealthStatusDisplay.formatRelativeTime(apiDto.timestamp),
statusLabel: HealthStatusDisplay.formatStatusLabel(apiDto.status),
statusColor: HealthStatusDisplay.formatStatusColor(apiDto.status),
statusIcon: HealthStatusDisplay.formatStatusIcon(apiDto.status),
formattedTimestamp: HealthStatusFormatter.formatTimestamp(apiDto.timestamp),
relativeTime: HealthStatusFormatter.formatRelativeTime(apiDto.timestamp),
statusLabel: HealthStatusFormatter.formatStatusLabel(apiDto.status),
statusColor: HealthStatusFormatter.formatStatusColor(apiDto.status),
statusIcon: HealthStatusFormatter.formatStatusIcon(apiDto.status),
};
// Build metrics
const metrics: HealthMetrics = {
uptime: HealthMetricDisplay.formatUptime(apiDto.uptime),
responseTime: HealthMetricDisplay.formatResponseTime(apiDto.responseTime),
errorRate: HealthMetricDisplay.formatErrorRate(apiDto.errorRate),
uptime: HealthMetricFormatter.formatUptime(apiDto.uptime),
responseTime: HealthMetricFormatter.formatResponseTime(apiDto.responseTime),
errorRate: HealthMetricFormatter.formatErrorRate(apiDto.errorRate),
lastCheck: apiDto.lastCheck || lastUpdated,
formattedLastCheck: HealthMetricDisplay.formatTimestamp(apiDto.lastCheck || lastUpdated),
formattedLastCheck: HealthMetricFormatter.formatTimestamp(apiDto.lastCheck || lastUpdated),
checksPassed: apiDto.checksPassed || 0,
checksFailed: apiDto.checksFailed || 0,
totalChecks: (apiDto.checksPassed || 0) + (apiDto.checksFailed || 0),
successRate: HealthMetricDisplay.formatSuccessRate(apiDto.checksPassed, apiDto.checksFailed),
successRate: HealthMetricFormatter.formatSuccessRate(apiDto.checksPassed, apiDto.checksFailed),
};
// Build components
const components: HealthComponent[] = (apiDto.components || []).map((component) => ({
name: component.name,
status: component.status,
statusLabel: HealthComponentDisplay.formatStatusLabel(component.status),
statusColor: HealthComponentDisplay.formatStatusColor(component.status),
statusIcon: HealthComponentDisplay.formatStatusIcon(component.status),
statusLabel: HealthComponentFormatter.formatStatusLabel(component.status),
statusColor: HealthComponentFormatter.formatStatusColor(component.status),
statusIcon: HealthComponentFormatter.formatStatusIcon(component.status),
lastCheck: component.lastCheck || lastUpdated,
formattedLastCheck: HealthComponentDisplay.formatTimestamp(component.lastCheck || lastUpdated),
responseTime: HealthMetricDisplay.formatResponseTime(component.responseTime),
errorRate: HealthMetricDisplay.formatErrorRate(component.errorRate),
formattedLastCheck: HealthComponentFormatter.formatTimestamp(component.lastCheck || lastUpdated),
responseTime: HealthMetricFormatter.formatResponseTime(component.responseTime),
errorRate: HealthMetricFormatter.formatErrorRate(component.errorRate),
}));
// Build alerts
@@ -57,10 +57,10 @@ export class HealthViewDataBuilder {
title: alert.title,
message: alert.message,
timestamp: alert.timestamp,
formattedTimestamp: HealthAlertDisplay.formatTimestamp(alert.timestamp),
relativeTime: HealthAlertDisplay.formatRelativeTime(alert.timestamp),
severity: HealthAlertDisplay.formatSeverity(alert.type),
severityColor: HealthAlertDisplay.formatSeverityColor(alert.type),
formattedTimestamp: HealthAlertFormatter.formatTimestamp(alert.timestamp),
relativeTime: HealthAlertFormatter.formatRelativeTime(alert.timestamp),
severity: HealthAlertFormatter.formatSeverity(alert.type),
severityColor: HealthAlertFormatter.formatSeverityColor(alert.type),
}));
// Calculate derived fields
@@ -77,7 +77,7 @@ export class HealthViewDataBuilder {
hasDegradedComponents,
hasErrorComponents,
lastUpdated,
formattedLastUpdated: HealthStatusDisplay.formatTimestamp(lastUpdated),
formattedLastUpdated: HealthStatusFormatter.formatTimestamp(lastUpdated),
};
}
}

View File

@@ -1,9 +1,9 @@
'use client';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { DashboardDateFormatter } from '@/lib/formatters/DashboardDateFormatter';
import type { DashboardOverviewDTO } from '@/lib/types/generated/DashboardOverviewDTO';
import type { HomeViewData } from '@/lib/view-data/HomeViewData';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { DashboardDateDisplay } from '@/lib/display-objects/DashboardDateDisplay';
export class HomeViewDataBuilder {
/**
@@ -19,7 +19,7 @@ export class HomeViewDataBuilder {
id: race.id,
track: race.track,
car: race.car,
formattedDate: DashboardDateDisplay.format(new Date(race.scheduledAt)).date,
formattedDate: DashboardDateFormatter.format(new Date(race.scheduledAt)).date,
})),
topLeagues: (apiDto.leagueStandingsSummaries || []).map(league => ({
id: league.leagueId,

View File

@@ -1,8 +1,8 @@
import type { LeagueRosterMemberDTO } from '@/lib/types/generated/LeagueRosterMemberDTO';
import type { LeagueRosterJoinRequestDTO } from '@/lib/types/generated/LeagueRosterJoinRequestDTO';
import type { LeagueRosterAdminViewData, RosterMemberData, JoinRequestData } from '@/lib/view-data/LeagueRosterAdminViewData';
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
import type { ViewDataBuilder } from '@/lib/contracts/builders/ViewDataBuilder';
import { DateFormatter } from '@/lib/formatters/DateFormatter';
import type { LeagueRosterJoinRequestDTO } from '@/lib/types/generated/LeagueRosterJoinRequestDTO';
import type { LeagueRosterMemberDTO } from '@/lib/types/generated/LeagueRosterMemberDTO';
import type { JoinRequestData, LeagueRosterAdminViewData, RosterMemberData } from '@/lib/view-data/LeagueRosterAdminViewData';
type LeagueRosterAdminInputDTO = {
leagueId: string;
@@ -23,7 +23,7 @@ export class LeagueRosterAdminViewDataBuilder {
},
role: member.role,
joinedAt: member.joinedAt,
formattedJoinedAt: DateDisplay.formatShort(member.joinedAt),
formattedJoinedAt: DateFormatter.formatShort(member.joinedAt),
}));
// Transform join requests
@@ -34,7 +34,7 @@ export class LeagueRosterAdminViewDataBuilder {
name: (req as { driver?: { name?: string } }).driver?.name || 'Unknown Driver',
},
requestedAt: req.requestedAt,
formattedRequestedAt: DateDisplay.formatShort(req.requestedAt),
formattedRequestedAt: DateFormatter.formatShort(req.requestedAt),
message: req.message ?? undefined,
}));

View File

@@ -1,5 +1,5 @@
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
import { StatusDisplay } from '@/lib/display-objects/StatusDisplay';
import { DateFormatter } from '@/lib/formatters/DateFormatter';
import { StatusFormatter } from '@/lib/formatters/StatusFormatter';
import { LeagueSponsorshipsApiDto } from '@/lib/types/tbd/LeagueSponsorshipsApiDto';
import { LeagueSponsorshipsViewData } from '@/lib/view-data/LeagueSponsorshipsViewData';
@@ -19,8 +19,8 @@ export class LeagueSponsorshipsViewDataBuilder implements ViewDataBuilder<any, a
sponsorshipSlots: apiDto.sponsorshipSlots,
sponsorshipRequests: apiDto.sponsorshipRequests.map(r => ({
...r,
formattedRequestedAt: DateDisplay.formatShort(r.requestedAt),
statusLabel: StatusDisplay.protestStatus(r.status), // Reusing protest status for now
formattedRequestedAt: DateFormatter.formatShort(r.requestedAt),
statusLabel: StatusFormatter.protestStatus(r.status), // Reusing protest status for now
})),
};
}

View File

@@ -1,12 +1,12 @@
import { mediaConfig } from '@/lib/config/mediaConfig';
import { CountryFlagFormatter } from '@/lib/formatters/CountryFlagFormatter';
import { DateFormatter } from '@/lib/formatters/DateFormatter';
import { FinishFormatter } from '@/lib/formatters/FinishFormatter';
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
import { PercentFormatter } from '@/lib/formatters/PercentFormatter';
import { RatingFormatter } from '@/lib/formatters/RatingFormatter';
import type { GetDriverProfileOutputDTO } from '@/lib/types/generated/GetDriverProfileOutputDTO';
import type { ProfileViewData } from '@/lib/view-data/ProfileViewData';
import { mediaConfig } from '@/lib/config/mediaConfig';
import { CountryFlagDisplay } from '@/lib/display-objects/CountryFlagDisplay';
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
import { FinishDisplay } from '@/lib/display-objects/FinishDisplay';
import { PercentDisplay } from '@/lib/display-objects/PercentDisplay';
import { RatingDisplay } from '@/lib/display-objects/RatingDisplay';
import { NumberDisplay } from '@/lib/display-objects/NumberDisplay';
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
@@ -24,7 +24,7 @@ export class ProfileViewDataBuilder implements ViewDataBuilder<any, any> {
id: '',
name: '',
countryCode: '',
countryFlag: CountryFlagDisplay.fromCountryCode(null).toString(),
countryFlag: CountryFlagFormatter.fromCountryCode(null).toString(),
avatarUrl: mediaConfig.avatars.defaultFallback,
bio: null,
iracingId: null,
@@ -45,25 +45,25 @@ export class ProfileViewDataBuilder implements ViewDataBuilder<any, any> {
id: driver.id,
name: driver.name,
countryCode: driver.country,
countryFlag: CountryFlagDisplay.fromCountryCode(driver.country).toString(),
countryFlag: CountryFlagFormatter.fromCountryCode(driver.country).toString(),
avatarUrl: driver.avatarUrl || mediaConfig.avatars.defaultFallback,
bio: driver.bio || null,
iracingId: driver.iracingId ? String(driver.iracingId) : null,
joinedAtLabel: DateDisplay.formatMonthYear(driver.joinedAt),
joinedAtLabel: DateFormatter.formatMonthYear(driver.joinedAt),
},
stats: stats
? {
ratingLabel: RatingDisplay.format(stats.rating),
ratingLabel: RatingFormatter.format(stats.rating),
globalRankLabel: driver.globalRank != null ? `#${driver.globalRank}` : '—',
totalRacesLabel: NumberDisplay.format(stats.totalRaces),
winsLabel: NumberDisplay.format(stats.wins),
podiumsLabel: NumberDisplay.format(stats.podiums),
dnfsLabel: NumberDisplay.format(stats.dnfs),
bestFinishLabel: FinishDisplay.format(stats.bestFinish),
worstFinishLabel: FinishDisplay.format(stats.worstFinish),
avgFinishLabel: FinishDisplay.formatAverage(stats.avgFinish),
consistencyLabel: PercentDisplay.formatWhole(stats.consistency),
percentileLabel: PercentDisplay.format(stats.percentile),
totalRacesLabel: NumberFormatter.format(stats.totalRaces),
winsLabel: NumberFormatter.format(stats.wins),
podiumsLabel: NumberFormatter.format(stats.podiums),
dnfsLabel: NumberFormatter.format(stats.dnfs),
bestFinishLabel: FinishFormatter.format(stats.bestFinish),
worstFinishLabel: FinishFormatter.format(stats.worstFinish),
avgFinishLabel: FinishFormatter.formatAverage(stats.avgFinish),
consistencyLabel: PercentFormatter.formatWhole(stats.consistency),
percentileLabel: PercentFormatter.format(stats.percentile),
}
: null,
teamMemberships: apiDto.teamMemberships.map((m) => ({
@@ -71,7 +71,7 @@ export class ProfileViewDataBuilder implements ViewDataBuilder<any, any> {
teamName: m.teamName,
teamTag: m.teamTag || null,
roleLabel: m.role,
joinedAtLabel: DateDisplay.formatMonthYear(m.joinedAt),
joinedAtLabel: DateFormatter.formatMonthYear(m.joinedAt),
href: `/teams/${m.teamId}`,
})),
extendedProfile: extended
@@ -92,18 +92,18 @@ export class ProfileViewDataBuilder implements ViewDataBuilder<any, any> {
id: a.id,
title: a.title,
description: a.description,
earnedAtLabel: DateDisplay.formatShort(a.earnedAt),
earnedAtLabel: DateFormatter.formatShort(a.earnedAt),
icon: a.icon as any,
rarityLabel: a.rarity,
})),
friends: socialSummary.friends.slice(0, 8).map((f) => ({
id: f.id,
name: f.name,
countryFlag: CountryFlagDisplay.fromCountryCode(f.country).toString(),
countryFlag: CountryFlagFormatter.fromCountryCode(f.country).toString(),
avatarUrl: f.avatarUrl || mediaConfig.avatars.defaultFallback,
href: `/drivers/${f.id}`,
})),
friendsCountLabel: NumberDisplay.format(socialSummary.friendsCount),
friendsCountLabel: NumberFormatter.format(socialSummary.friendsCount),
}
: null,
};

View File

@@ -1,8 +1,8 @@
import { DateFormatter } from '@/lib/formatters/DateFormatter';
import { RaceStatusFormatter } from '@/lib/formatters/RaceStatusFormatter';
import { RelativeTimeFormatter } from '@/lib/formatters/RelativeTimeFormatter';
import type { RacesPageDataDTO } from '@/lib/types/generated/RacesPageDataDTO';
import type { RacesViewData, RaceViewData } from '@/lib/view-data/RacesViewData';
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
import { RaceStatusDisplay } from '@/lib/display-objects/RaceStatusDisplay';
import { RelativeTimeDisplay } from '@/lib/display-objects/RelativeTimeDisplay';
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
@@ -19,13 +19,13 @@ export class RacesViewDataBuilder implements ViewDataBuilder<any, any> {
track: race.track,
car: race.car,
scheduledAt: race.scheduledAt,
scheduledAtLabel: DateDisplay.formatShort(race.scheduledAt),
timeLabel: DateDisplay.formatTime(race.scheduledAt),
relativeTimeLabel: RelativeTimeDisplay.format(race.scheduledAt, now),
scheduledAtLabel: DateFormatter.formatShort(race.scheduledAt),
timeLabel: DateFormatter.formatTime(race.scheduledAt),
relativeTimeLabel: RelativeTimeFormatter.format(race.scheduledAt, now),
status: race.status as RaceViewData['status'],
statusLabel: RaceStatusDisplay.getLabel(race.status),
statusVariant: RaceStatusDisplay.getVariant(race.status),
statusIconName: RaceStatusDisplay.getIconName(race.status),
statusLabel: RaceStatusFormatter.getLabel(race.status),
statusVariant: RaceStatusFormatter.getVariant(race.status),
statusIconName: RaceStatusFormatter.getIconName(race.status),
sessionType: 'Race',
leagueId: race.leagueId,
leagueName: race.leagueName,

View File

@@ -1,9 +1,9 @@
import { DateFormatter } from '@/lib/formatters/DateFormatter';
import { LeagueFormatter } from '@/lib/formatters/LeagueFormatter';
import { MemberFormatter } from '@/lib/formatters/MemberFormatter';
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
import type { GetTeamDetailsOutputDTO } from '@/lib/types/generated/GetTeamDetailsOutputDTO';
import type { TeamDetailViewData, TeamDetailData, TeamMemberData, SponsorMetric, TeamTab } from '@/lib/view-data/TeamDetailViewData';
import { DateDisplay } from '@/lib/display-objects/DateDisplay';
import { MemberDisplay } from '@/lib/display-objects/MemberDisplay';
import { LeagueDisplay } from '@/lib/display-objects/LeagueDisplay';
import { NumberDisplay } from '@/lib/display-objects/NumberDisplay';
import type { SponsorMetric, TeamDetailData, TeamDetailViewData, TeamMemberData, TeamTab } from '@/lib/view-data/TeamDetailViewData';
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
@@ -21,7 +21,7 @@ export class TeamDetailViewDataBuilder implements ViewDataBuilder<any, any> {
ownerId: apiDto.team.ownerId,
leagues: (apiDto.team as any).leagues || [],
createdAt: apiDto.team.createdAt,
foundedDateLabel: apiDto.team.createdAt ? DateDisplay.formatMonthYear(apiDto.team.createdAt) : 'Unknown',
foundedDateLabel: apiDto.team.createdAt ? DateFormatter.formatMonthYear(apiDto.team.createdAt) : 'Unknown',
specialization: (apiDto.team as any).specialization || null,
region: (apiDto.team as any).region || null,
languages: (apiDto.team as any).languages || [],
@@ -35,7 +35,7 @@ export class TeamDetailViewDataBuilder implements ViewDataBuilder<any, any> {
driverName: membership.driverName,
role: membership.role,
joinedAt: membership.joinedAt,
joinedAtLabel: DateDisplay.formatShort(membership.joinedAt),
joinedAtLabel: DateFormatter.formatShort(membership.joinedAt),
isActive: membership.isActive,
avatarUrl: membership.avatarUrl,
}));
@@ -51,19 +51,19 @@ export class TeamDetailViewDataBuilder implements ViewDataBuilder<any, any> {
{
icon: 'users',
label: 'Members',
value: NumberDisplay.format(memberships.length),
value: NumberFormatter.format(memberships.length),
color: 'text-primary-blue',
},
{
icon: 'zap',
label: 'Est. Reach',
value: NumberDisplay.format(memberships.length * 15),
value: NumberFormatter.format(memberships.length * 15),
color: 'text-purple-400',
},
{
icon: 'calendar',
label: 'Races',
value: NumberDisplay.format(leagueCount),
value: NumberFormatter.format(leagueCount),
color: 'text-neon-aqua',
},
{
@@ -89,8 +89,8 @@ export class TeamDetailViewDataBuilder implements ViewDataBuilder<any, any> {
isAdmin,
teamMetrics,
tabs,
memberCountLabel: MemberDisplay.formatCount(memberships.length),
leagueCountLabel: LeagueDisplay.formatCount(leagueCount),
memberCountLabel: MemberFormatter.formatCount(memberships.length),
leagueCountLabel: LeagueFormatter.formatCount(leagueCount),
};
}
}

View File

@@ -1,8 +1,8 @@
import { NumberFormatter } from '@/lib/formatters/NumberFormatter';
import { RatingFormatter } from '@/lib/formatters/RatingFormatter';
import type { GetAllTeamsOutputDTO } from '@/lib/types/generated/GetAllTeamsOutputDTO';
import type { TeamsViewData, TeamSummaryData } from '@/lib/view-data/TeamsViewData';
import type { TeamListItemDTO } from '@/lib/types/generated/TeamListItemDTO';
import { RatingDisplay } from '@/lib/display-objects/RatingDisplay';
import { NumberDisplay } from '@/lib/display-objects/NumberDisplay';
import type { TeamSummaryData, TeamsViewData } from '@/lib/view-data/TeamsViewData';
import { ViewDataBuilder } from "../../contracts/builders/ViewDataBuilder";
@@ -17,10 +17,10 @@ export class TeamsViewDataBuilder implements ViewDataBuilder<any, any> {
teamName: team.name,
memberCount: team.memberCount,
logoUrl: team.logoUrl || '',
ratingLabel: RatingDisplay.format(team.rating),
ratingLabel: RatingFormatter.format(team.rating),
ratingValue: team.rating || 0,
winsLabel: NumberDisplay.format(team.totalWins || 0),
racesLabel: NumberDisplay.format(team.totalRaces || 0),
winsLabel: NumberFormatter.format(team.totalWins || 0),
racesLabel: NumberFormatter.format(team.totalRaces || 0),
region: team.region || '',
isRecruiting: team.isRecruiting,
category: team.category || '',