37 lines
1.3 KiB
TypeScript
37 lines
1.3 KiB
TypeScript
import { LeagueRepository } from '../ports/LeagueRepository';
|
|
import { DriverRepository } from '../../../racing/domain/repositories/DriverRepository';
|
|
import { EventPublisher } from '../../../shared/ports/EventPublisher';
|
|
import { ApproveMembershipRequestCommand } from '../ports/ApproveMembershipRequestCommand';
|
|
|
|
export class ApproveMembershipRequestUseCase {
|
|
constructor(
|
|
private readonly leagueRepository: LeagueRepository,
|
|
private readonly driverRepository: DriverRepository,
|
|
private readonly eventPublisher: EventPublisher,
|
|
) {}
|
|
|
|
async execute(command: ApproveMembershipRequestCommand): Promise<void> {
|
|
const league = await this.leagueRepository.findById(command.leagueId);
|
|
if (!league) {
|
|
throw new Error('League not found');
|
|
}
|
|
|
|
const requests = await this.leagueRepository.getPendingRequests(command.leagueId);
|
|
const request = requests.find(r => r.id === command.requestId);
|
|
if (!request) {
|
|
throw new Error('Request not found');
|
|
}
|
|
|
|
await this.leagueRepository.addLeagueMembers(command.leagueId, [
|
|
{
|
|
driverId: request.driverId,
|
|
name: request.name,
|
|
role: 'member',
|
|
joinDate: new Date(),
|
|
},
|
|
]);
|
|
|
|
await this.leagueRepository.removePendingRequest(command.leagueId, command.requestId);
|
|
}
|
|
}
|