refactor use cases
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import { Logger, UseCaseOutputPort } from '@core/shared/application';
|
||||
import { Logger } from '@core/shared/application';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
|
||||
import type { IProtestRepository } from '../../domain/repositories/IProtestRepository';
|
||||
@@ -33,16 +33,13 @@ export type SubmitProtestDefenseErrorCode =
|
||||
| 'REPOSITORY_ERROR';
|
||||
|
||||
export class SubmitProtestDefenseUseCase {
|
||||
constructor(
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
constructor(private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly protestRepository: IProtestRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<SubmitProtestDefenseResult>,
|
||||
) {}
|
||||
private readonly logger: Logger) {}
|
||||
|
||||
async execute(
|
||||
input: SubmitProtestDefenseInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<SubmitProtestDefenseErrorCode, { message: string }>>> {
|
||||
): Promise<Result<SubmitProtestDefenseResult, ApplicationErrorCode<SubmitProtestDefenseErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const league = await this.leagueRepository.findById(input.leagueId);
|
||||
if (!league) {
|
||||
@@ -84,9 +81,7 @@ export class SubmitProtestDefenseUseCase {
|
||||
status: 'defense_submitted',
|
||||
};
|
||||
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error: unknown) {
|
||||
const message =
|
||||
error instanceof Error && typeof error.message === 'string'
|
||||
|
||||
Reference in New Issue
Block a user