service 的 updateProfile 已存在但 controller 未注册路由, Profile 页保存资料 404。新增 UpdateProfileDto(nickname/avatar 可选, 白名单校验),与契约 §2 对齐。 Co-Authored-By: Claude <noreply@anthropic.com>
27 lines
1.0 KiB
TypeScript
27 lines
1.0 KiB
TypeScript
import { Body, Controller, Get, Patch, UseGuards } from '@nestjs/common';
|
|
import { ApiBearerAuth, ApiOkResponse, ApiOperation, ApiTags } from '@nestjs/swagger';
|
|
import { CurrentUser, JwtPayload } from '../common/decorators/current-user.decorator';
|
|
import { UsersService } from './users.service';
|
|
import { UpdateProfileDto } from './dto/update-profile.dto';
|
|
|
|
@ApiTags('用户')
|
|
@ApiBearerAuth()
|
|
@Controller('users')
|
|
export class UsersController {
|
|
constructor(private readonly usersService: UsersService) {}
|
|
|
|
@Get('me')
|
|
@ApiOperation({ summary: '获取当前登录用户信息' })
|
|
@ApiOkResponse({ description: '当前用户' })
|
|
async getMe(@CurrentUser() user: JwtPayload) {
|
|
return this.usersService.findById(user.sub);
|
|
}
|
|
|
|
@Patch('me')
|
|
@ApiOperation({ summary: '更新当前用户资料(昵称/头像)' })
|
|
@ApiOkResponse({ description: '更新后的用户' })
|
|
async updateMe(@CurrentUser() user: JwtPayload, @Body() dto: UpdateProfileDto) {
|
|
return this.usersService.updateProfile(user.sub, dto);
|
|
}
|
|
}
|