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

@@ -15,7 +15,10 @@ export interface RemoveLeagueMemberResult {
removedRole: string;
}
export type RemoveLeagueMemberErrorCode = 'MEMBERSHIP_NOT_FOUND' | 'REPOSITORY_ERROR';
export type RemoveLeagueMemberErrorCode =
| 'MEMBERSHIP_NOT_FOUND'
| 'CANNOT_REMOVE_LAST_OWNER'
| 'REPOSITORY_ERROR';
export class RemoveLeagueMemberUseCase {
constructor(
@@ -39,6 +42,18 @@ export class RemoveLeagueMemberUseCase {
});
}
if (membership.role.toString() === 'owner') {
const members = await this.leagueMembershipRepository.getLeagueMembers(params.leagueId);
const ownerCount = members.filter(m => m.role.toString() === 'owner').length;
if (ownerCount <= 1) {
return Result.err({
code: 'CANNOT_REMOVE_LAST_OWNER',
details: { message: 'Cannot remove the last owner' },
});
}
}
const updatedMembership = LeagueMembership.create({
id: membership.id,
leagueId: membership.leagueId.toString(),