Some checks failed
CI / lint-typecheck (pull_request) Failing after 4m50s
CI / tests (pull_request) Has been skipped
CI / contract-tests (pull_request) Has been skipped
CI / e2e-tests (pull_request) Has been skipped
CI / comment-pr (pull_request) Has been skipped
CI / commit-types (pull_request) Has been skipped
37 lines
1.2 KiB
TypeScript
37 lines
1.2 KiB
TypeScript
import { LeagueRepository } from '../ports/LeagueRepository';
|
|
import { DriverRepository } from '../ports/DriverRepository';
|
|
import { EventPublisher } from '../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);
|
|
}
|
|
}
|