From 3fc65e50bfc1a36d225b147f4218ce0558c305a2 Mon Sep 17 00:00:00 2001 From: lhmin0604 Date: Sat, 12 Sep 2026 04:39:35 +0800 Subject: [PATCH] =?UTF-8?q?feat(users):=20=E8=A1=A5=E9=BD=90=20PATCH=20/ap?= =?UTF-8?q?i/users/me=EF=BC=88=E5=A5=91=E7=BA=A6=20=C2=A72=20=E9=81=97?= =?UTF-8?q?=E6=BC=8F=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit service 的 updateProfile 已存在但 controller 未注册路由, Profile 页保存资料 404。新增 UpdateProfileDto(nickname/avatar 可选, 白名单校验),与契约 §2 对齐。 Co-Authored-By: Claude --- src/users/dto/update-profile.dto.ts | 17 +++++++++++++++++ src/users/users.controller.ts | 10 +++++++++- 2 files changed, 26 insertions(+), 1 deletion(-) create mode 100644 src/users/dto/update-profile.dto.ts diff --git a/src/users/dto/update-profile.dto.ts b/src/users/dto/update-profile.dto.ts new file mode 100644 index 0000000..0207a80 --- /dev/null +++ b/src/users/dto/update-profile.dto.ts @@ -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; +} diff --git a/src/users/users.controller.ts b/src/users/users.controller.ts index ec7793c..60d307a 100644 --- a/src/users/users.controller.ts +++ b/src/users/users.controller.ts @@ -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); + } }