refactor use cases

This commit is contained in:
2026-01-08 15:34:51 +01:00
parent d984ab24a8
commit 52e9a2f6a7
362 changed files with 5192 additions and 8409 deletions

View File

@@ -7,7 +7,6 @@
import type { IPrizeRepository } from '../../domain/repositories/IPrizeRepository';
import type { PrizeType, 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';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
@@ -28,14 +27,13 @@ export interface CreatePrizeResult {
export type CreatePrizeErrorCode = 'PRIZE_ALREADY_EXISTS';
export class CreatePrizeUseCase
implements UseCase<CreatePrizeInput, void, CreatePrizeErrorCode>
implements UseCase<CreatePrizeInput, CreatePrizeResult, CreatePrizeErrorCode>
{
constructor(
private readonly prizeRepository: IPrizeRepository,
private readonly output: UseCaseOutputPort<CreatePrizeResult>,
) {}
async execute(input: CreatePrizeInput): Promise<Result<void, ApplicationErrorCode<CreatePrizeErrorCode>>> {
async execute(input: CreatePrizeInput): Promise<Result<CreatePrizeResult, ApplicationErrorCode<CreatePrizeErrorCode>>> {
const { leagueId, seasonId, position, name, amount, type, description } = input;
const existingPrize = await this.prizeRepository.findByPosition(leagueId, seasonId, position);
@@ -59,8 +57,6 @@ export class CreatePrizeUseCase
const createdPrize = await this.prizeRepository.create(prize);
this.output.present({ prize: createdPrize });
return Result.ok(undefined);
return Result.ok({ prize: createdPrize });
}
}