refactor core presenters
This commit is contained in:
@@ -2,7 +2,7 @@ import type { ITeamMembershipRepository } from '../../domain/repositories/ITeamM
|
||||
import type { IDriverRepository } from '../../domain/repositories/IDriverRepository';
|
||||
import type { GetDriverAvatarInputPort } from '../ports/input/GetDriverAvatarInputPort';
|
||||
import type { GetDriverAvatarOutputPort } from '../ports/output/GetDriverAvatarOutputPort';
|
||||
import type { TeamJoinRequestsResultDTO } from '../presenters/ITeamJoinRequestsPresenter';
|
||||
import type { TeamJoinRequestsOutputPort } from '../ports/output/TeamJoinRequestsOutputPort';
|
||||
import { Result } from '@core/shared/application/Result';
|
||||
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
|
||||
import type { AsyncUseCase } from '@core/shared/application';
|
||||
@@ -11,7 +11,7 @@ import type { Logger } from '@core/shared/application';
|
||||
/**
|
||||
* Use Case for retrieving team join requests.
|
||||
*/
|
||||
export class GetTeamJoinRequestsUseCase implements AsyncUseCase<{ teamId: string }, TeamJoinRequestsResultDTO, 'REPOSITORY_ERROR'>
|
||||
export class GetTeamJoinRequestsUseCase implements AsyncUseCase<{ teamId: string }, TeamJoinRequestsOutputPort, 'REPOSITORY_ERROR'>
|
||||
{
|
||||
constructor(
|
||||
private readonly membershipRepository: ITeamMembershipRepository,
|
||||
@@ -20,7 +20,7 @@ export class GetTeamJoinRequestsUseCase implements AsyncUseCase<{ teamId: string
|
||||
private readonly logger: Logger,
|
||||
) {}
|
||||
|
||||
async execute(input: { teamId: string }): Promise<Result<TeamJoinRequestsResultDTO, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
|
||||
async execute(input: { teamId: string }): Promise<Result<TeamJoinRequestsOutputPort, ApplicationErrorCode<'REPOSITORY_ERROR'>>> {
|
||||
this.logger.debug('Executing GetTeamJoinRequestsUseCase', { teamId: input.teamId });
|
||||
|
||||
try {
|
||||
@@ -33,7 +33,7 @@ export class GetTeamJoinRequestsUseCase implements AsyncUseCase<{ teamId: string
|
||||
for (const request of requests) {
|
||||
const driver = await this.driverRepository.findById(request.driverId);
|
||||
if (driver) {
|
||||
driverNames[request.driverId] = driver.name;
|
||||
driverNames[request.driverId] = driver.name.value;
|
||||
} else {
|
||||
this.logger.warn(`Driver not found for ID: ${request.driverId} during join request processing.`);
|
||||
}
|
||||
@@ -43,13 +43,23 @@ export class GetTeamJoinRequestsUseCase implements AsyncUseCase<{ teamId: string
|
||||
this.logger.debug('Processed driver details for join request', { driverId: request.driverId });
|
||||
}
|
||||
|
||||
const dto: TeamJoinRequestsResultDTO = {
|
||||
requests,
|
||||
driverNames,
|
||||
avatarUrls,
|
||||
const requestsViewModel = requests.map(request => ({
|
||||
requestId: request.id,
|
||||
driverId: request.driverId,
|
||||
driverName: driverNames[request.driverId] || 'Unknown',
|
||||
teamId: request.teamId,
|
||||
status: request.status as 'pending' | 'approved' | 'rejected',
|
||||
requestedAt: request.requestedAt instanceof Date ? request.requestedAt : new Date(request.requestedAt),
|
||||
avatarUrl: avatarUrls[request.driverId] || '',
|
||||
}));
|
||||
|
||||
const outputPort: TeamJoinRequestsOutputPort = {
|
||||
requests: requestsViewModel,
|
||||
pendingCount: requests.filter(r => r.status === 'pending').length,
|
||||
totalCount: requests.length,
|
||||
};
|
||||
|
||||
return Result.ok(dto);
|
||||
return Result.ok(outputPort);
|
||||
} catch (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