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); + } }