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 { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { Team } from '../../domain/entities/Team';
|
||||
@@ -27,13 +27,12 @@ export class JoinTeamUseCase {
|
||||
private readonly teamRepository: ITeamRepository,
|
||||
private readonly membershipRepository: ITeamMembershipRepository,
|
||||
private readonly logger: Logger,
|
||||
private readonly output: UseCaseOutputPort<JoinTeamResult>,
|
||||
) {}
|
||||
|
||||
async execute(
|
||||
input: JoinTeamInput,
|
||||
): Promise<
|
||||
Result<void, ApplicationErrorCode<JoinTeamErrorCode, { message: string }>>
|
||||
Result<JoinTeamResult, ApplicationErrorCode<JoinTeamErrorCode, { message: string }>>
|
||||
> {
|
||||
this.logger.debug('Attempting to join team', { input });
|
||||
const { teamId, driverId } = input;
|
||||
@@ -86,12 +85,10 @@ export class JoinTeamUseCase {
|
||||
await this.membershipRepository.saveMembership(membership);
|
||||
this.logger.info('Driver successfully joined team', { driverId, teamId });
|
||||
|
||||
this.output.present({
|
||||
return Result.ok({
|
||||
team,
|
||||
membership: savedMembership,
|
||||
});
|
||||
|
||||
return Result.ok(undefined);
|
||||
} catch (error) {
|
||||
this.logger.error(
|
||||
'Failed to join team due to an unexpected error',
|
||||
|
||||
Reference in New Issue
Block a user