first commit

This commit is contained in:
lendry
2026-06-24 14:37:15 +03:00
commit 995adeedd4
188 changed files with 28810 additions and 0 deletions

View File

@@ -0,0 +1,130 @@
import { Body, Controller, Delete, ForbiddenException, Get, Headers, Param, Patch, Post } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiTags } from '@nestjs/swagger';
import { firstValueFrom } from 'rxjs';
import { map } from 'rxjs/operators';
import { CoreGrpcService } from '../core-grpc.service';
import { getAuthorizedUserId } from '../document-access';
import { AddFamilyMemberDto, CreateFamilyGroupDto, RespondFamilyInviteDto, SendFamilyInviteDto, UpdateFamilyGroupDto } from '../dto/identity.dto';
@ApiTags('Семья')
@ApiBearerAuth()
@Controller('family')
export class FamilyController {
constructor(
private readonly core: CoreGrpcService,
private readonly jwt: JwtService
) {}
private async auth(authorization?: string) {
return getAuthorizedUserId(this.jwt, this.core, authorization);
}
@Post('groups')
@ApiOperation({ summary: 'Создать семейную группу' })
@ApiBody({ type: CreateFamilyGroupDto })
async createGroup(@Headers('authorization') authorization: string | undefined, @Body() dto: CreateFamilyGroupDto) {
const userId = await this.auth(authorization);
if (dto.ownerId !== userId) {
throw new ForbiddenException('Можно создавать семью только от своего имени');
}
return firstValueFrom(this.core.family.CreateFamilyGroup(dto));
}
@Get('users/:userId/groups')
@ApiOperation({ summary: 'Список семей пользователя' })
async listGroups(@Headers('authorization') authorization: string | undefined, @Param('userId') userId: string) {
const requesterId = await this.auth(authorization);
if (requesterId !== userId) {
throw new ForbiddenException('Можно просматривать только свои семьи');
}
return firstValueFrom(
this.core.family.ListFamilyGroups({ userId }).pipe(
map((response) => {
const payload = response as { groups?: unknown[] };
return { groups: payload.groups ?? [] };
})
)
);
}
@Get('groups/:groupId')
@ApiOperation({ summary: 'Получить семейную группу' })
async getGroup(@Headers('authorization') authorization: string | undefined, @Param('groupId') groupId: string) {
const requesterId = await this.auth(authorization);
return firstValueFrom(this.core.family.GetFamilyGroup({ requesterId, groupId }));
}
@Patch('groups/:groupId')
@ApiOperation({ summary: 'Обновить семейную группу' })
async updateGroup(
@Headers('authorization') authorization: string | undefined,
@Param('groupId') groupId: string,
@Body() dto: UpdateFamilyGroupDto
) {
const requesterId = await this.auth(authorization);