refactor
This commit is contained in:
@@ -1,31 +1,25 @@
|
||||
import type { AllLeaguesWithCapacityOutputPort } from '@core/racing/application/ports/output/AllLeaguesWithCapacityOutputPort';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import { AllLeaguesWithCapacityDTO, LeagueWithCapacityDTO } from '../dtos/AllLeaguesWithCapacityDTO';
|
||||
import type { GetAllLeaguesWithCapacityResult } from '@core/racing/application/use-cases/GetAllLeaguesWithCapacityUseCase';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
export class AllLeaguesWithCapacityPresenter {
|
||||
private result: AllLeaguesWithCapacityDTO | null = null;
|
||||
|
||||
reset() {
|
||||
this.result = null;
|
||||
}
|
||||
|
||||
present(output: AllLeaguesWithCapacityOutputPort) {
|
||||
export class AllLeaguesWithCapacityPresenter implements UseCaseOutputPort<GetAllLeaguesWithCapacityResult, 'REPOSITORY_ERROR'> {
|
||||
present(result: Result<GetAllLeaguesWithCapacityResult, ApplicationErrorCode<'REPOSITORY_ERROR'>>): AllLeaguesWithCapacityDTO {
|
||||
const output = result.unwrap();
|
||||
const leagues: LeagueWithCapacityDTO[] = output.leagues.map(league => ({
|
||||
id: league.id,
|
||||
name: league.name,
|
||||
description: league.description,
|
||||
ownerId: league.ownerId,
|
||||
settings: { maxDrivers: league.settings.maxDrivers || 0 },
|
||||
createdAt: league.createdAt.toISOString(),
|
||||
usedSlots: output.memberCounts[league.id] || 0,
|
||||
socialLinks: league.socialLinks,
|
||||
id: league.league.id.toString(),
|
||||
name: league.league.name.toString(),
|
||||
description: league.league.description?.toString() || '',
|
||||
ownerId: league.league.ownerId.toString(),
|
||||
settings: { maxDrivers: league.maxDrivers },
|
||||
createdAt: league.league.createdAt.toDate().toISOString(),
|
||||
usedSlots: league.currentDrivers,
|
||||
socialLinks: league.league.socialLinks || {},
|
||||
}));
|
||||
this.result = {
|
||||
return {
|
||||
leagues,
|
||||
totalCount: leagues.length,
|
||||
};
|
||||
}
|
||||
|
||||
getViewModel(): AllLeaguesWithCapacityDTO | null {
|
||||
return this.result;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user