refactor
This commit is contained in:
@@ -5,29 +5,29 @@
|
||||
*/
|
||||
|
||||
import type { IPrizeRepository } from '../../domain/repositories/IPrizeRepository';
|
||||
import type {
|
||||
IGetPrizesPresenter,
|
||||
GetPrizesResultDTO,
|
||||
GetPrizesViewModel,
|
||||
} from '../presenters/IGetPrizesPresenter';
|
||||
import type { Prize } from '../../domain/entities/Prize';
|
||||
import type { UseCase } from '@core/shared/application/UseCase';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application/UseCaseOutputPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
|
||||
export interface GetPrizesInput {
|
||||
leagueId: string;
|
||||
seasonId?: string;
|
||||
}
|
||||
|
||||
export interface GetPrizesResult {
|
||||
prizes: Prize[];
|
||||
}
|
||||
|
||||
export class GetPrizesUseCase
|
||||
implements UseCase<GetPrizesInput, GetPrizesResultDTO, GetPrizesViewModel, IGetPrizesPresenter>
|
||||
implements UseCase<GetPrizesInput, void, never>
|
||||
{
|
||||
constructor(private readonly prizeRepository: IPrizeRepository) {}
|
||||
|
||||
async execute(
|
||||
input: GetPrizesInput,
|
||||
presenter: IGetPrizesPresenter,
|
||||
): Promise<void> {
|
||||
presenter.reset();
|
||||
constructor(
|
||||
private readonly prizeRepository: IPrizeRepository,
|
||||
private readonly output: UseCaseOutputPort<GetPrizesResult>,
|
||||
) {}
|
||||
|
||||
async execute(input: GetPrizesInput): Promise<Result<void, never>> {
|
||||
const { leagueId, seasonId } = input;
|
||||
|
||||
let prizes;
|
||||
@@ -39,23 +39,8 @@ export class GetPrizesUseCase
|
||||
|
||||
prizes.sort((a, b) => a.position - b.position);
|
||||
|
||||
const dto: GetPrizesResultDTO = {
|
||||
prizes: prizes.map(prize => ({
|
||||
id: prize.id,
|
||||
leagueId: prize.leagueId,
|
||||
seasonId: prize.seasonId,
|
||||
position: prize.position,
|
||||
name: prize.name,
|
||||
amount: prize.amount,
|
||||
type: prize.type,
|
||||
description: prize.description,
|
||||
awarded: prize.awarded,
|
||||
awardedTo: prize.awardedTo,
|
||||
awardedAt: prize.awardedAt,
|
||||
createdAt: prize.createdAt,
|
||||
})),
|
||||
};
|
||||
this.output.present({ prizes });
|
||||
|
||||
presenter.present(dto);
|
||||
return Result.ok(undefined);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user