我无法公开对象数组。尽管我在UserDto
这就是我得到的,
{
"id": "5ff4ec30-d3f4-43d3-b5ad-82b03e1c5481",
"userName": "jdbfjl",
"email": "jdfbaj@gmail.com",
"bio": "Duuude",
"avatar": "sjldflaeulajsnlnaefb",
"followerCount": 0,
"followeeCount": 0,
"verified": false,
"followers": [
{},
{},
{}
],
"followees": [
{}
]
}
Run Code Online (Sandbox Code Playgroud)
预期就像
{
"id": "5ff4ec30-d3f4-43d3-b5ad-82b03e1c5481",
"createdAt": "2021-08-11T11:07:11.688Z",
"updatedAt": "2021-08-11T11:07:11.688Z",
"userName": "ashdviah",
"email": "hsdvhas@gmail.com",
"bio": "I am Handsome",
"avatar": "sjldflaeulajsnlnaefb",
"followerCount": 0,
"followeeCount": 0,
"verified": false,
"followers": [
{
"id": "db1d30c6-5607-4d87-8838-69f906c3c44e",
"createdAt": "2021-08-11T11:09:33.018Z",
"updatedAt": "2021-08-11T11:09:33.018Z"
},
{
"id": "31492cd6-7c56-48f6-aff3-792a980b5100",
"createdAt": "2021-08-11T11:11:01.288Z",
"updatedAt": "2021-08-11T11:11:01.288Z"
},
],
"followees": [
{
"id": "ab095d0d-b9fa-41a4-be35-13fe9dd6f7a1",
"createdAt": …Run Code Online (Sandbox Code Playgroud) 我在 Nestjs 中有这个基本的 CRUD 方法。我面临的问题是,当我getCurrentUserId()在所有方法的顶部应用该方法时,它工作正常,但当我在底部应用该方法时,它不起作用并给出错误。中间件有什么问题吗?
user.controller.ts
@Controller('users')
@Serialize(UserDto)
export class UsersController {
constructor(private usersService: UsersService) {}
@Post('/signup')
create(@Body() createUserDto: CreateUserDto): Promise<User> {
return this.usersService.create(createUserDto);
}
@Get('/@:userName')
async getUserByUsername(@Param('userName') userName: string) {
const user = await this.usersService.findByName(userName);
console.log(userName);
if (!user) {
throw new NotFoundException('User Not Found');
}
return user;
}
//! Testing for current user
@Get('/current')
@UseGuards(JwtAuthGuard)
async getCurrentUserId(@CurrentUser() id: string) {
console.log('running endpoint');
return id;
}
}
Run Code Online (Sandbox Code Playgroud)
current-user.decorator.ts
import { createParamDecorator, ExecutionContext } from '@nestjs/common';
export const CurrentUser …Run Code Online (Sandbox Code Playgroud)