refactor use cases
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import type { Logger, UseCaseOutputPort } from '@core/shared/application';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
import type { ILeagueMembershipRepository } from '@core/racing/domain/repositories/ILeagueMembershipRepository';
|
||||
import { LeagueMembership } from '../../domain/entities/LeagueMembership';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
@@ -19,10 +19,9 @@ export class JoinLeagueUseCase {
|
||||
constructor(
|
||||
private readonly membershipRepository: ILeagueMembershipRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<JoinLeagueResult>,
|
||||
) {}
|
||||
|
||||
async execute(command: JoinLeagueInput): Promise<Result<void, ApplicationErrorCode<JoinLeagueErrorCode, { message: string }>>> {
|
||||
async execute(command: JoinLeagueInput): Promise<Result<JoinLeagueResult, ApplicationErrorCode<JoinLeagueErrorCode, { message: string }>>> {
|
||||
this.logger.debug('Attempting to join league', { command });
|
||||
const { leagueId, driverId } = command;
|
||||
|
||||
@@ -46,11 +45,9 @@ export class JoinLeagueUseCase {
|
||||
const savedMembership = await this.membershipRepository.saveMembership(membership);
|
||||
this.logger.info('Successfully joined league', { membershipId: savedMembership.id });
|
||||
|
||||
this.output.present({
|
||||
return Result.ok({
|
||||
membership: savedMembership,
|
||||
});
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
const err = error instanceof Error ? error : new Error('Unknown error');
|
||||
this.logger.error('Failed to join league due to an unexpected error', err);
|
||||
@@ -60,4 +57,4 @@ export class JoinLeagueUseCase {
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user