modify bugs

This commit is contained in:
2025-07-04 10:26:05 +08:00
parent 0d11d2bd8a
commit 730b77448e
4 changed files with 14 additions and 15 deletions
@@ -1,11 +1,11 @@
import { Paramtype, SetMetadata } from '@nestjs/common';
import { ClassTransformOptions } from 'class-transformer';
import { ValidationOptions } from 'class-validator';
import { ClassTransformOptions } from '@nestjs/common/interfaces/external/class-transform-options.interface';
import { ValidatorOptions } from '@nestjs/common/interfaces/external/validator-options.interface';
import { DTO_VALIDATION_OPTIONS } from '../contants';
export const DtoValidation = (
options?: ValidationOptions & { transformOptions?: ClassTransformOptions } & {
options?: ValidatorOptions & { transformOptions?: ClassTransformOptions } & {
type?: Paramtype;
},
) => SetMetadata(DTO_VALIDATION_OPTIONS, options ?? {});
@@ -7,6 +7,7 @@ import {
Request,
SerializeOptions,
UseGuards,
UseInterceptors,
} from '@nestjs/common';
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
@@ -14,6 +15,8 @@ import { pick } from 'lodash';
import { Depends } from '@/modules/restful/decorators/depend.decorator';
import { UserIdInterceptor } from '@/modules/user/interceptors';
import { Guest } from '../decorators/guest.decorator';
import { RequestUser } from '../decorators/user.request.decorator';
import { UpdateAccountDto, UpdatePasswordDto } from '../dtos/account.dto';
@@ -83,8 +86,13 @@ export class AccountController {
*/
@Patch()
@ApiBearerAuth()
@UseInterceptors(UserIdInterceptor)
@SerializeOptions({ groups: ['user-detail'] })
async update(@RequestUser() user: ClassToPlain<UserEntity>, @Body() data: UpdateAccountDto) {
async update(
@RequestUser() user: ClassToPlain<UserEntity>,
@Body()
data: UpdateAccountDto,
) {
return this.userService.update({ id: user.id, ...pick(data, ['username', 'nickname']) });
}
+2 -9
View File
@@ -11,15 +11,8 @@ import { UserValidateGroup } from '../constants';
/**
* 更新用户信息
*/
@DtoValidation({ groups: [UserValidateGroup.ACCOUNT_UPDATE] })
export class UpdateAccountDto extends PickType(UserCommonDto, ['username', 'nickname']) {
/**
* 待更新的用户ID
*/
@IsUUID(undefined, { message: '用户ID格式不正确', groups: [UserValidateGroup.USER_UPDATE] })
@IsDefined({ groups: ['update'], message: '用户ID必须指定' })
id?: string;
}
@DtoValidation({ groups: [UserValidateGroup.ACCOUNT_UPDATE], whitelist: false })
export class UpdateAccountDto extends PickType(UserCommonDto, ['username', 'nickname']) {}
/**
* 更改用户密码