refactor use cases
This commit is contained in:
@@ -7,7 +7,6 @@
|
||||
import type { IPrizeRepository } from '../../domain/repositories/IPrizeRepository';
|
||||
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';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
|
||||
@@ -23,14 +22,13 @@ export interface AwardPrizeResult {
|
||||
export type AwardPrizeErrorCode = 'PRIZE_NOT_FOUND' | 'PRIZE_ALREADY_AWARDED';
|
||||
|
||||
export class AwardPrizeUseCase
|
||||
implements UseCase<AwardPrizeInput, void, AwardPrizeErrorCode>
|
||||
implements UseCase<AwardPrizeInput, AwardPrizeResult, AwardPrizeErrorCode>
|
||||
{
|
||||
constructor(
|
||||
private readonly prizeRepository: IPrizeRepository,
|
||||
private readonly output: UseCaseOutputPort<AwardPrizeResult>,
|
||||
) {}
|
||||
|
||||
async execute(input: AwardPrizeInput): Promise<Result<void, ApplicationErrorCode<AwardPrizeErrorCode>>> {
|
||||
async execute(input: AwardPrizeInput): Promise<Result<AwardPrizeResult, ApplicationErrorCode<AwardPrizeErrorCode>>> {
|
||||
const { prizeId, driverId } = input;
|
||||
|
||||
const prize = await this.prizeRepository.findById(prizeId);
|
||||
@@ -48,8 +46,6 @@ export class AwardPrizeUseCase
|
||||
|
||||
const updatedPrize = await this.prizeRepository.update(prize);
|
||||
|
||||
this.output.present({ prize: updatedPrize });
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok({ prize: updatedPrize });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user