Add for leave family

This commit is contained in:
lendry
2026-06-27 00:15:36 +03:00
parent 1a30e7e21c
commit 4b86c64cc4
17 changed files with 323 additions and 31 deletions

View File

@@ -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, {

View File

@@ -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;