refactor
This commit is contained in:
@@ -1,34 +1,26 @@
|
||||
import type { ITeamMembershipRepository } from '../../domain/repositories/ITeamMembershipRepository';
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type { IImageServicePort } from '../ports/IImageServicePort';
|
||||
import type {
|
||||
ITeamJoinRequestsPresenter,
|
||||
TeamJoinRequestsResultDTO,
|
||||
TeamJoinRequestsViewModel,
|
||||
} from '../presenters/ITeamJoinRequestsPresenter';
|
||||
import type { UseCase } from '@core/shared/application';
|
||||
import type { TeamJoinRequestsResultDTO } from '../presenters/ITeamJoinRequestsPresenter';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
import type { Logger } from '@core/shared/application';
|
||||
|
||||
/**
|
||||
* Use Case for retrieving team join requests.
|
||||
* Orchestrates domain logic and delegates presentation to the presenter.
|
||||
*/
|
||||
export class GetTeamJoinRequestsUseCase
|
||||
implements UseCase<{ teamId: string }, TeamJoinRequestsResultDTO, TeamJoinRequestsViewModel, ITeamJoinRequestsPresenter>
|
||||
export class GetTeamJoinRequestsUseCase implements AsyncUseCase<{ teamId: string }, TeamJoinRequestsResultDTO, 'REPOSITORY_ERROR'>
|
||||
{
|
||||
constructor(
|
||||
private readonly membershipRepository: ITeamMembershipRepository,
|
||||
private readonly driverRepository: IDriverRepository,
|
||||
private readonly imageService: IImageServicePort,
|
||||
private readonly logger: Logger,
|
||||
// Kept for backward compatibility; callers must pass their own presenter.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||
public readonly presenter: ITeamJoinRequestsPresenter,
|
||||
) {}
|
||||
|
||||
async execute(input: { teamId: string }, presenter: ITeamJoinRequestsPresenter): Promise<void> {
|
||||
async execute(input: { teamId: string }): Promise<Result<TeamJoinRequestsResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
|
||||
this.logger.debug('Executing GetTeamJoinRequestsUseCase', { teamId: input.teamId });
|
||||
presenter.reset();
|
||||
|
||||
try {
|
||||
const requests = await this.membershipRepository.getJoinRequests(input.teamId);
|
||||
@@ -54,10 +46,10 @@ export class GetTeamJoinRequestsUseCase
|
||||
avatarUrls,
|
||||
};
|
||||
|
||||
presenter.present(dto);
|
||||
return Result.ok(dto);
|
||||
} catch (error) {
|
||||
this.logger.error('Error retrieving team join requests', { teamId: input.teamId, error });
|
||||
throw error;
|
||||
this.logger.error('Error retrieving team join requests', { teamId: input.teamId, err: error });
|
||||
return Result.err({ code: 'REPOSITORY_ERROR', details: { message: 'Failed to retrieve team join requests' } });
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user