modify bugs
This commit is contained in:
parent
0d11d2bd8a
commit
730b77448e
@ -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']) });
|
||||
}
|
||||
|
||||
|
@ -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']) {}
|
||||
|
||||
/**
|
||||
* 更改用户密码
|
||||
|
@ -324,7 +324,6 @@ describe('AccountController (App)', () => {
|
||||
},
|
||||
});
|
||||
const { token } = loginResult.json();
|
||||
console.log(token);
|
||||
const result = await app.inject({
|
||||
method: 'POST',
|
||||
url: `${URL_PREFIX}/account/logout`,
|
||||
@ -449,7 +448,6 @@ describe('AccountController (App)', () => {
|
||||
username: `updated-account-${randomTag}`,
|
||||
},
|
||||
});
|
||||
console.log(result.json());
|
||||
expect(result.statusCode).toBe(200);
|
||||
const updatedUser = result.json();
|
||||
expect(updatedUser.username).toBe(`updated-account-${randomTag}`);
|
||||
|
Loading…
Reference in New Issue
Block a user