first commit
This commit is contained in:
83
apps/api-gateway/src/controllers/profile.controller.ts
Normal file
83
apps/api-gateway/src/controllers/profile.controller.ts
Normal 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 });
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user