refactor
This commit is contained in:
41
apps/api/src/domain/team/presenters/DriverTeamPresenter.ts
Normal file
41
apps/api/src/domain/team/presenters/DriverTeamPresenter.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
import { IDriverTeamPresenter, DriverTeamResultDTO, DriverTeamViewModel } from '@core/racing/application/presenters/IDriverTeamPresenter';
|
||||
|
||||
export class DriverTeamPresenter implements IDriverTeamPresenter {
|
||||
private result: DriverTeamViewModel | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(dto: DriverTeamResultDTO) {
|
||||
const isOwner = dto.team.ownerId === dto.driverId;
|
||||
const canManage = isOwner || dto.membership.role === 'owner' || dto.membership.role === 'manager';
|
||||
|
||||
this.result = {
|
||||
team: {
|
||||
id: dto.team.id,
|
||||
name: dto.team.name,
|
||||
tag: dto.team.tag,
|
||||
description: dto.team.description || '',
|
||||
ownerId: dto.team.ownerId,
|
||||
leagues: dto.team.leagues || [],
|
||||
},
|
||||
membership: {
|
||||
role: dto.membership.role as 'owner' | 'manager' | 'member',
|
||||
joinedAt: dto.membership.joinedAt.toISOString(),
|
||||
isActive: dto.membership.status === 'active',
|
||||
},
|
||||
isOwner,
|
||||
canManage,
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): DriverTeamViewModel | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): DriverTeamViewModel {
|
||||
if (!this.result) throw new Error('Presenter not presented');
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user