feat(users): 补齐 PATCH /api/users/me(契约 §2 遗漏)

service 的 updateProfile 已存在但 controller 未注册路由,
Profile 页保存资料 404。新增 UpdateProfileDto(nickname/avatar 可选,
白名单校验),与契约 §2 对齐。

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-09-12 04:39:35 +08:00
co-authored by Claude
parent 0a3c8e834d
commit 3fc65e50bf
2 changed files with 26 additions and 1 deletions
+17
View File
@@ -0,0 +1,17 @@
import { ApiPropertyOptional } from '@nestjs/swagger';
import { IsOptional, IsString, MaxLength } from 'class-validator';
/** PATCH /api/users/me:昵称/头像可选更新(契约 §2) */
export class UpdateProfileDto {
@ApiPropertyOptional({ description: '昵称' })
@IsOptional()
@IsString()
@MaxLength(50)
nickname?: string;
@ApiPropertyOptional({ description: '头像 URL' })
@IsOptional()
@IsString()
@MaxLength(500)
avatar?: string;
}
+9 -1
View File
@@ -1,7 +1,8 @@
import { Controller, Get, UseGuards } from '@nestjs/common';
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()
@@ -15,4 +16,11 @@ export class UsersController {
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);
}
}