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,83 @@
import { Body, Controller, ForbiddenException, Get, Headers, Param, Patch, Post } from '@nestjs/common';
import { JwtService } from '@nestjs/jwt';
import { ApiBearerAuth, ApiBody, ApiOperation, ApiParam, ApiResponse, ApiTags } from '@nestjs/swagger';
import { CoreGrpcService } from '../core-grpc.service';
import { getAuthorizedUserId } from '../document-access';
import { SetPasswordDto, UpdateAvatarDto, UpdateContactsDto, UpdateProfileDto } from '../dto/profile.dto';
@ApiTags('Профиль и биометрия')
@ApiBearerAuth()
@Controller('profile/users/:userId')
export class ProfileController {
constructor(
private readonly core: CoreGrpcService,
private readonly jwt: JwtService
) {}
private async assertSelfAccess(authorization: string | undefined, userId: string) {
const requesterId = await getAuthorizedUserId(this.jwt, this.core, authorization);
if (requesterId !== userId) {
throw new ForbiddenException('Можно изменять только свой профиль');
}
return requesterId;
}
@Get()
@ApiOperation({ summary: 'Получить профиль пользователя', description: 'Возвращает публичный профиль, аватар и основные/резервные контакты пользователя.' })
@ApiParam({ name: 'userId', description: 'ID пользователя' })
@ApiResponse({ status: 200, description: 'Профиль пользователя успешно получен' })
@ApiResponse({ status: 404, description: 'Пользователь не найден' })
getProfile(@Param('userId') userId: string) {
return this.core.profile.GetProfile({ userId });
}
@Patch('avatar')
@ApiOperation({ summary: 'Обновить аватар', description: 'Сохраняет URL или ключ объекта MinIO как аватар пользователя.' })
@ApiParam({ name: 'userId', description: 'ID пользователя' })
@ApiBody({ type: UpdateAvatarDto })
@ApiResponse({ status: 200, description: 'Аватар обновлен' })
updateAvatar(@Param('userId') userId: string, @Body() dto: UpdateAvatarDto) {
return this.core.profile.UpdateAvatar({ userId, avatarUrl: dto.avatarUrl, avatarStorageKey: dto.avatarStorageKey });
}