wip league admin tools

This commit is contained in:
2025-12-28 12:04:12 +01:00
parent 5dc8c2399c
commit 6edf12fda8
401 changed files with 15365 additions and 6047 deletions

View File

@@ -1,4 +1,5 @@
import type { ILeagueMembershipRepository } from '../../domain/repositories/ILeagueMembershipRepository';
import type { ILeagueRepository } from '../../domain/repositories/ILeagueRepository';
import { Result } from '@core/shared/application/Result';
import type { ApplicationErrorCode } from '@core/shared/errors/ApplicationErrorCode';
import { randomUUID } from 'crypto';
@@ -11,7 +12,7 @@ import { MembershipStatus } from '../../domain/entities/MembershipStatus';
export interface ApproveLeagueJoinRequestInput {
leagueId: string;
requestId: string;
joinRequestId: string;
}
export interface ApproveLeagueJoinRequestResult {
@@ -22,19 +23,40 @@ export interface ApproveLeagueJoinRequestResult {
export class ApproveLeagueJoinRequestUseCase {
constructor(
private readonly leagueMembershipRepository: ILeagueMembershipRepository,
private readonly leagueRepository: ILeagueRepository,
) {}
async execute(
input: ApproveLeagueJoinRequestInput,
output: UseCaseOutputPort<ApproveLeagueJoinRequestResult>,
): Promise<Result<void, ApplicationErrorCode<'JOIN_REQUEST_NOT_FOUND'>>> {
): Promise<
Result<
void,
ApplicationErrorCode<
'JOIN_REQUEST_NOT_FOUND' | 'LEAGUE_NOT_FOUND' | 'LEAGUE_AT_CAPACITY',
{ message: string }
>
>
> {
const requests = await this.leagueMembershipRepository.getJoinRequests(input.leagueId);
const request = requests.find(r => r.id === input.requestId);
const request = requests.find(r => r.id === input.joinRequestId);
if (!request) {
return Result.err({ code: 'JOIN_REQUEST_NOT_FOUND' });
return Result.err({ code: 'JOIN_REQUEST_NOT_FOUND', details: { message: 'Join request not found' } });
}
await this.leagueMembershipRepository.removeJoinRequest(input.requestId);
const league = await this.leagueRepository.findById(input.leagueId);
if (!league) {
return Result.err({ code: 'LEAGUE_NOT_FOUND', details: { message: 'League not found' } });
}
const members = await this.leagueMembershipRepository.getLeagueMembers(input.leagueId);
const maxDrivers = league.settings.maxDrivers ?? 32;
if (members.length >= maxDrivers) {
return Result.err({ code: 'LEAGUE_AT_CAPACITY', details: { message: 'League is at capacity' } });
}
await this.leagueMembershipRepository.removeJoinRequest(input.joinRequestId);
await this.leagueMembershipRepository.saveMembership({
id: randomUUID(),
leagueId: LeagueId.create(input.leagueId),