refactor core presenters
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
|
||||
import type { AllLeaguesWithCapacityResultDTO } from '../presenters/IAllLeaguesWithCapacityPresenter';
|
||||
import type { AllLeaguesWithCapacityOutputPort } from '../ports/output/AllLeaguesWithCapacityOutputPort';
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
import { Result } from '@/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
@@ -10,17 +10,17 @@ import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorC
|
||||
* Orchestrates domain logic and returns result.
|
||||
*/
|
||||
export class GetAllLeaguesWithCapacityUseCase
|
||||
implements AsyncUseCase<void, AllLeaguesWithCapacityResultDTO, string>
|
||||
implements AsyncUseCase<void, AllLeaguesWithCapacityOutputPort, string>
|
||||
{
|
||||
constructor(
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly leagueMembershipRepository: ILeagueMembershipRepository,
|
||||
) {}
|
||||
|
||||
async execute(): Promise<Result<AllLeaguesWithCapacityResultDTO, ApplicationErrorCode<string>>> {
|
||||
async execute(): Promise<Result<AllLeaguesWithCapacityOutputPort, ApplicationErrorCode<string>>> {
|
||||
const leagues = await this.leagueRepository.findAll();
|
||||
|
||||
const memberCounts = new Map<string, number>();
|
||||
const memberCounts: Record<string, number> = {};
|
||||
|
||||
for (const league of leagues) {
|
||||
const members = await this.leagueMembershipRepository.getLeagueMembers(league.id);
|
||||
@@ -34,14 +34,14 @@ export class GetAllLeaguesWithCapacityUseCase
|
||||
m.role === 'member'),
|
||||
).length;
|
||||
|
||||
memberCounts.set(league.id, usedSlots);
|
||||
memberCounts[league.id] = usedSlots;
|
||||
}
|
||||
|
||||
const dto: AllLeaguesWithCapacityResultDTO = {
|
||||
const output: AllLeaguesWithCapacityOutputPort = {
|
||||
leagues,
|
||||
memberCounts,
|
||||
};
|
||||
|
||||
return Result.ok(dto);
|
||||
return Result.ok(output);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user