view data fixes
This commit is contained in:
@@ -19,7 +19,83 @@ export function useDriverProfile(
|
||||
const error = result.getError();
|
||||
throw new ApiError(error.message, 'SERVER_ERROR', { timestamp: new globalThis.Date().toISOString() });
|
||||
}
|
||||
return new DriverProfileViewModel(result.unwrap());
|
||||
const dto = result.unwrap();
|
||||
// Convert GetDriverProfileOutputDTO to ProfileViewData
|
||||
const viewData: ProfileViewData = {
|
||||
driver: dto.currentDriver ? {
|
||||
id: dto.currentDriver.id,
|
||||
name: dto.currentDriver.name,
|
||||
countryCode: dto.currentDriver.countryCode || '',
|
||||
countryFlag: dto.currentDriver.countryFlag || '',
|
||||
avatarUrl: dto.currentDriver.avatarUrl || '',
|
||||
bio: dto.currentDriver.bio || null,
|
||||
iracingId: dto.currentDriver.iracingId || null,
|
||||
joinedAtLabel: dto.currentDriver.joinedAt || '',
|
||||
globalRankLabel: dto.currentDriver.globalRank || '',
|
||||
} : {
|
||||
id: '',
|
||||
name: '',
|
||||
countryCode: '',
|
||||
countryFlag: '',
|
||||
avatarUrl: '',
|
||||
bio: null,
|
||||
iracingId: null,
|
||||
joinedAtLabel: '',
|
||||
globalRankLabel: '',
|
||||
},
|
||||
stats: dto.stats ? {
|
||||
ratingLabel: dto.stats.rating || '',
|
||||
globalRankLabel: dto.stats.globalRank || '',
|
||||
totalRacesLabel: dto.stats.totalRaces?.toString() || '',
|
||||
winsLabel: dto.stats.wins?.toString() || '',
|
||||
podiumsLabel: dto.stats.podiums?.toString() || '',
|
||||
dnfsLabel: dto.stats.dnfs?.toString() || '',
|
||||
bestFinishLabel: dto.stats.bestFinish?.toString() || '',
|
||||
worstFinishLabel: dto.stats.worstFinish?.toString() || '',
|
||||
avgFinishLabel: dto.stats.avgFinish?.toString() || '',
|
||||
consistencyLabel: dto.stats.consistency?.toString() || '',
|
||||
percentileLabel: dto.stats.percentile?.toString() || '',
|
||||
} : null,
|
||||
teamMemberships: dto.teamMemberships.map(m => ({
|
||||
teamId: m.teamId,
|
||||
teamName: m.teamName,
|
||||
teamTag: m.teamTag || null,
|
||||
roleLabel: m.role || '',
|
||||
joinedAtLabel: m.joinedAt || '',
|
||||
href: `/teams/${m.teamId}`,
|
||||
})),
|
||||
extendedProfile: dto.extendedProfile ? {
|
||||
timezone: dto.extendedProfile.timezone || '',
|
||||
racingStyle: dto.extendedProfile.racingStyle || '',
|
||||
favoriteTrack: dto.extendedProfile.favoriteTrack || '',
|
||||
favoriteCar: dto.extendedProfile.favoriteCar || '',
|
||||
availableHours: dto.extendedProfile.availableHours || '',
|
||||
lookingForTeamLabel: dto.extendedProfile.lookingForTeam ? 'Yes' : 'No',
|
||||
openToRequestsLabel: dto.extendedProfile.openToRequests ? 'Yes' : 'No',
|
||||
socialHandles: dto.extendedProfile.socialHandles?.map(h => ({
|
||||
platformLabel: h.platform || '',
|
||||
handle: h.handle || '',
|
||||
url: h.url || '',
|
||||
})) || [],
|
||||
achievements: dto.extendedProfile.achievements?.map(a => ({
|
||||
id: a.id,
|
||||
title: a.title,
|
||||
description: a.description,
|
||||
earnedAtLabel: a.earnedAt || '',
|
||||
icon: a.icon as any,
|
||||
rarityLabel: a.rarity || '',
|
||||
})) || [],
|
||||
friends: dto.extendedProfile.friends?.map(f => ({
|
||||
id: f.id,
|
||||
name: f.name,
|
||||
countryFlag: f.countryFlag || '',
|
||||
avatarUrl: f.avatarUrl || '',
|
||||
href: `/drivers/${f.id}`,
|
||||
})) || [],
|
||||
friendsCountLabel: dto.extendedProfile.friendsCount?.toString() || '',
|
||||
} : null,
|
||||
};
|
||||
return new DriverProfileViewModel(viewData);
|
||||
},
|
||||
enabled: !!driverId,
|
||||
...options,
|
||||
|
||||
@@ -14,24 +14,29 @@ export function useLeagueWalletPageData(leagueId: string) {
|
||||
queryKey: ['leagueWallet', leagueId],
|
||||
queryFn: async () => {
|
||||
const dto = await leagueWalletService.getWalletForLeague(leagueId);
|
||||
// Transform DTO to ViewModel at client boundary
|
||||
const transactions = dto.transactions.map(t => new WalletTransactionViewModel({
|
||||
// Transform DTO to ViewData at client boundary
|
||||
const transactions = dto.transactions.map(t => ({
|
||||
id: t.id,
|
||||
type: t.type as any,
|
||||
description: t.description,
|
||||
amount: t.amount,
|
||||
fee: 0,
|
||||
netAmount: t.amount,
|
||||
date: new globalThis.Date(t.createdAt),
|
||||
date: new globalThis.Date(t.createdAt).toISOString(),
|
||||
status: t.status,
|
||||
}));
|
||||
return new LeagueWalletViewModel({
|
||||
leagueId,
|
||||
balance: dto.balance,
|
||||
currency: dto.currency,
|
||||
formattedBalance: '',
|
||||
totalRevenue: dto.balance, // Fallback
|
||||
formattedTotalRevenue: '',
|
||||
totalFees: 0,
|
||||
formattedTotalFees: '',
|
||||
totalWithdrawals: 0,
|
||||
pendingPayouts: 0,
|
||||
formattedPendingPayouts: '',
|
||||
currency: dto.currency,
|
||||
transactions,
|
||||
canWithdraw: true,
|
||||
withdrawalBlockReason: undefined,
|
||||
|
||||
Reference in New Issue
Block a user