modify bugs
This commit is contained in:
parent
0d11d2bd8a
commit
730b77448e
@ -1,11 +1,11 @@
|
|||||||
import { Paramtype, SetMetadata } from '@nestjs/common';
|
import { Paramtype, SetMetadata } from '@nestjs/common';
|
||||||
import { ClassTransformOptions } from 'class-transformer';
|
import { ClassTransformOptions } from '@nestjs/common/interfaces/external/class-transform-options.interface';
|
||||||
import { ValidationOptions } from 'class-validator';
|
import { ValidatorOptions } from '@nestjs/common/interfaces/external/validator-options.interface';
|
||||||
|
|
||||||
import { DTO_VALIDATION_OPTIONS } from '../contants';
|
import { DTO_VALIDATION_OPTIONS } from '../contants';
|
||||||
|
|
||||||
export const DtoValidation = (
|
export const DtoValidation = (
|
||||||
options?: ValidationOptions & { transformOptions?: ClassTransformOptions } & {
|
options?: ValidatorOptions & { transformOptions?: ClassTransformOptions } & {
|
||||||
type?: Paramtype;
|
type?: Paramtype;
|
||||||
},
|
},
|
||||||
) => SetMetadata(DTO_VALIDATION_OPTIONS, options ?? {});
|
) => SetMetadata(DTO_VALIDATION_OPTIONS, options ?? {});
|
||||||
|
@ -7,6 +7,7 @@ import {
|
|||||||
Request,
|
Request,
|
||||||
SerializeOptions,
|
SerializeOptions,
|
||||||
UseGuards,
|
UseGuards,
|
||||||
|
UseInterceptors,
|
||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
import { ApiBearerAuth, ApiTags } from '@nestjs/swagger';
|
||||||
|
|
||||||
@ -14,6 +15,8 @@ import { pick } from 'lodash';
|
|||||||
|
|
||||||
import { Depends } from '@/modules/restful/decorators/depend.decorator';
|
import { Depends } from '@/modules/restful/decorators/depend.decorator';
|
||||||
|
|
||||||
|
import { UserIdInterceptor } from '@/modules/user/interceptors';
|
||||||
|
|
||||||
import { Guest } from '../decorators/guest.decorator';
|
import { Guest } from '../decorators/guest.decorator';
|
||||||
import { RequestUser } from '../decorators/user.request.decorator';
|
import { RequestUser } from '../decorators/user.request.decorator';
|
||||||
import { UpdateAccountDto, UpdatePasswordDto } from '../dtos/account.dto';
|
import { UpdateAccountDto, UpdatePasswordDto } from '../dtos/account.dto';
|
||||||
@ -83,8 +86,13 @@ export class AccountController {
|
|||||||
*/
|
*/
|
||||||
@Patch()
|
@Patch()
|
||||||
@ApiBearerAuth()
|
@ApiBearerAuth()
|
||||||
|
@UseInterceptors(UserIdInterceptor)
|
||||||
@SerializeOptions({ groups: ['user-detail'] })
|
@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']) });
|
return this.userService.update({ id: user.id, ...pick(data, ['username', 'nickname']) });
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,15 +11,8 @@ import { UserValidateGroup } from '../constants';
|
|||||||
/**
|
/**
|
||||||
* 更新用户信息
|
* 更新用户信息
|
||||||
*/
|
*/
|
||||||
@DtoValidation({ groups: [UserValidateGroup.ACCOUNT_UPDATE] })
|
@DtoValidation({ groups: [UserValidateGroup.ACCOUNT_UPDATE], whitelist: false })
|
||||||
export class UpdateAccountDto extends PickType(UserCommonDto, ['username', 'nickname']) {
|
export class UpdateAccountDto extends PickType(UserCommonDto, ['username', 'nickname']) {}
|
||||||
/**
|
|
||||||
* 待更新的用户ID
|
|
||||||
*/
|
|
||||||
@IsUUID(undefined, { message: '用户ID格式不正确', groups: [UserValidateGroup.USER_UPDATE] })
|
|
||||||
@IsDefined({ groups: ['update'], message: '用户ID必须指定' })
|
|
||||||
id?: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 更改用户密码
|
* 更改用户密码
|
||||||
|
@ -324,7 +324,6 @@ describe('AccountController (App)', () => {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
const { token } = loginResult.json();
|
const { token } = loginResult.json();
|
||||||
console.log(token);
|
|
||||||
const result = await app.inject({
|
const result = await app.inject({
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
url: `${URL_PREFIX}/account/logout`,
|
url: `${URL_PREFIX}/account/logout`,
|
||||||
@ -449,7 +448,6 @@ describe('AccountController (App)', () => {
|
|||||||
username: `updated-account-${randomTag}`,
|
username: `updated-account-${randomTag}`,
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
console.log(result.json());
|
|
||||||
expect(result.statusCode).toBe(200);
|
expect(result.statusCode).toBe(200);
|
||||||
const updatedUser = result.json();
|
const updatedUser = result.json();
|
||||||
expect(updatedUser.username).toBe(`updated-account-${randomTag}`);
|
expect(updatedUser.username).toBe(`updated-account-${randomTag}`);
|
||||||
|
Loading…
Reference in New Issue
Block a user