refactor use cases
This commit is contained in:
@@ -3,8 +3,6 @@ import type { ILeagueRepository } from '../../domain/repositories/ILeagueReposit
|
||||
import type { SeasonStatus } from '../../domain/value-objects/SeasonStatus';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { UseCaseOutputPort } from '@core/shared/application';
|
||||
|
||||
export type SeasonLifecycleTransition =
|
||||
| 'activate'
|
||||
| 'complete'
|
||||
@@ -39,15 +37,12 @@ export type ManageSeasonLifecycleErrorCode =
|
||||
* ManageSeasonLifecycleUseCase
|
||||
*/
|
||||
export class ManageSeasonLifecycleUseCase {
|
||||
constructor(
|
||||
private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly seasonRepository: ISeasonRepository,
|
||||
private readonly output: UseCaseOutputPort<ManageSeasonLifecycleResult>,
|
||||
) {}
|
||||
constructor(private readonly leagueRepository: ILeagueRepository,
|
||||
private readonly seasonRepository: ISeasonRepository) {}
|
||||
|
||||
async execute(
|
||||
input: ManageSeasonLifecycleInput,
|
||||
): Promise<Result<void, ApplicationErrorCode<ManageSeasonLifecycleErrorCode, { message: string }>>> {
|
||||
): Promise<Result<ManageSeasonLifecycleResult, ApplicationErrorCode<ManageSeasonLifecycleErrorCode, { message: string }>>> {
|
||||
try {
|
||||
const league = await this.leagueRepository.findById(input.leagueId);
|
||||
if (!league) {
|
||||
@@ -104,9 +99,7 @@ export class ManageSeasonLifecycleUseCase {
|
||||
},
|
||||
};
|
||||
|
||||
this.output.present(result);
|
||||
|
||||
return Result.ok(undefined);
|
||||
return Result.ok(result);
|
||||
} catch (error) {
|
||||
return Result.err({
|
||||
code: 'REPOSITORY_ERROR',
|
||||
|
||||
Reference in New Issue
Block a user