Files
gridpilot.gg/apps/api/src/domain/driver/presenters/DriverProfilePresenter.ts
2025-12-21 19:53:22 +01:00

62 lines
2.4 KiB
TypeScript

import type {
GetProfileOverviewResult,
} from '@core/racing/application/use-cases/GetProfileOverviewUseCase';
import type { GetDriverProfileOutputDTO } from '../dtos/GetDriverProfileOutputDTO';
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
export class DriverProfilePresenter
implements UseCaseOutputPort<GetProfileOverviewResult>
{
private responseModel: GetDriverProfileOutputDTO | null = null;
present(result: GetProfileOverviewResult): void {
this.responseModel = {
currentDriver: result.driverInfo
? {
id: result.driverInfo.driver.id,
name: result.driverInfo.driver.name.toString(),
country: result.driverInfo.driver.country.toString(),
avatarUrl: this.getAvatarUrl(result.driverInfo.driver.id) || '',
iracingId: result.driverInfo.driver.iracingId.toString(),
joinedAt: result.driverInfo.driver.joinedAt.toDate().toISOString(),
rating: result.driverInfo.rating,
globalRank: result.driverInfo.globalRank,
consistency: result.driverInfo.consistency,
bio: result.driverInfo.driver.bio?.toString() || null,
totalDrivers: result.driverInfo.totalDrivers,
}
: null,
stats: result.stats,
finishDistribution: result.finishDistribution,
teamMemberships: result.teamMemberships.map(membership => ({
teamId: membership.team.id,
teamName: membership.team.name.toString(),
teamTag: membership.team.tag.toString(),
role: membership.membership.role,
joinedAt: membership.membership.joinedAt.toISOString(),
isCurrent: true, // TODO: check membership status
})),
socialSummary: {
friendsCount: result.socialSummary.friendsCount,
friends: result.socialSummary.friends.map(friend => ({
id: friend.id,
name: friend.name.toString(),
country: friend.country.toString(),
avatarUrl: '', // TODO: get avatar
})),
},
extendedProfile: result.extendedProfile as any,
};
}
getResponseModel(): GetDriverProfileOutputDTO {
if (!this.responseModel) throw new Error('Presenter not presented');
return this.responseModel;
}
private getAvatarUrl(driverId: string): string | undefined {
// Avatar resolution is delegated to infrastructure; keep as-is for now.
return undefined;
}
}