Add for leave family
This commit is contained in:
@@ -912,6 +912,11 @@ export class AuthGrpcController {
|
||||
return this.family.leaveFamily(command.requesterId, command.groupId, command.newOwnerUserId);
|
||||
}
|
||||
|
||||
@GrpcMethod('FamilyService', 'TransferFamilyOwnership')
|
||||
transferFamilyOwnership(command: { requesterId: string; groupId: string; newOwnerUserId: string }) {
|
||||
return this.family.transferFamilyOwnership(command.requesterId, command.groupId, command.newOwnerUserId);
|
||||
}
|
||||
|
||||
@GrpcMethod('FamilyService', 'SendFamilyInvite')
|
||||
async sendFamilyInvite(command: { requesterId: string; groupId: string; target?: string; inviteeUserId?: string }) {
|
||||
const invite = await this.family.sendInvite(command.requesterId, command.groupId, {
|
||||
|
||||
@@ -282,6 +282,34 @@ export class FamilyService {
|
||||
|
||||
}
|
||||
|
||||
async transferFamilyOwnership(requesterId: string, groupId: string, newOwnerUserId: string) {
|
||||
|
||||
const group = await this.getGroupWithMembers(groupId);
|
||||
|
||||
this.assertOwner(group, requesterId);
|
||||
|
||||
if (newOwnerUserId === requesterId) {
|
||||
|
||||
throw new BadRequestException('Нельзя передать семью самому себе');
|
||||
|
||||
}
|
||||
|
||||
const otherHumans = this.getHumanMembers(group.members).filter((item) => item.userId !== requesterId);
|
||||
|
||||
if (!otherHumans.some((item) => item.userId === newOwnerUserId)) {
|
||||
|
||||
throw new BadRequestException('Новый глава семьи должен быть участником семьи');
|
||||
|
||||
}
|
||||
|
||||
await this.transferOwnership(group, requesterId, newOwnerUserId);
|
||||
|
||||
const updated = await this.getGroupWithMembers(groupId);
|
||||
|
||||
return this.toGroup(updated, requesterId);
|
||||
|
||||
}
|
||||
|
||||
private async destroyGroupWithCleanup(group: {
|
||||
|
||||
id: string;
|
||||
|
||||
Reference in New Issue
Block a user