refactor core presenters
This commit is contained in:
@@ -1,50 +1,36 @@
|
||||
import {
|
||||
ITeamDetailsPresenter,
|
||||
TeamDetailsResultDTO,
|
||||
TeamDetailsViewModel,
|
||||
} from '@core/racing/application/presenters/ITeamDetailsPresenter';
|
||||
import type { GetTeamDetailsOutputPort } from '@core/racing/application/ports/output/GetTeamDetailsOutputPort';
|
||||
import type { GetTeamDetailsOutputDTO } from '../dtos/GetTeamDetailsOutputDTO';
|
||||
|
||||
export class TeamDetailsPresenter implements ITeamDetailsPresenter {
|
||||
private result: TeamDetailsViewModel | null = null;
|
||||
export class TeamDetailsPresenter {
|
||||
private result: GetTeamDetailsOutputDTO | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(dto: TeamDetailsResultDTO) {
|
||||
const { team, membership } = dto;
|
||||
|
||||
const canManage =
|
||||
membership !== null &&
|
||||
(membership.role === 'owner' || membership.role === 'manager');
|
||||
|
||||
async present(outputPort: GetTeamDetailsOutputPort): Promise<void> {
|
||||
this.result = {
|
||||
team: {
|
||||
id: team.id,
|
||||
name: team.name,
|
||||
tag: team.tag,
|
||||
description: team.description,
|
||||
ownerId: team.ownerId,
|
||||
leagues: team.leagues || [],
|
||||
createdAt: team.createdAt?.toISOString() || new Date().toISOString(),
|
||||
id: outputPort.team.id,
|
||||
name: outputPort.team.name,
|
||||
tag: outputPort.team.tag,
|
||||
description: outputPort.team.description,
|
||||
ownerId: outputPort.team.ownerId,
|
||||
leagues: outputPort.team.leagues,
|
||||
createdAt: outputPort.team.createdAt.toISOString(),
|
||||
},
|
||||
membership: membership
|
||||
membership: outputPort.membership
|
||||
? {
|
||||
role: membership.role as 'owner' | 'manager' | 'member',
|
||||
joinedAt: membership.joinedAt.toISOString(),
|
||||
isActive: membership.status === 'active',
|
||||
role: outputPort.membership.role,
|
||||
joinedAt: outputPort.membership.joinedAt.toISOString(),
|
||||
isActive: outputPort.membership.isActive,
|
||||
}
|
||||
: null,
|
||||
canManage,
|
||||
canManage: outputPort.canManage,
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): TeamDetailsViewModel | null {
|
||||
return this.result;
|
||||
}
|
||||
|
||||
get viewModel(): TeamDetailsViewModel {
|
||||
if (!this.result) throw new Error('Presenter not presented');
|
||||
getViewModel(): GetTeamDetailsOutputDTO | null {
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user