wip league admin tools
This commit is contained in:
@@ -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(),
|
||||
|
||||
Reference in New Issue
Block a user