Reputation: 501
If have the following route which should return the username and city of a user.
Controller:
@HttpCode(200)
@Get(':userId')
async getUserUnauthenticated(@Param("userId") userId: string): Promise<GetUserDto> {
return this.usersService.getUsers(userId, false)
}
Service:
async getUsers(userId: string, authenticated: boolean): Promise<GetUserDto> {
const user = await this.fusionAuthService.searchUserById(userId);
const impacter = await this.impactersService.retrieveImpacterFromDatabaseById(userId)
if (authenticated) {
return {
username: user.username,
city: impacter.address.city,
image: user.imageUrl
}
} else {
return {
username: user.username,
city: impacter.address.city
}
}
}
DTO:
export class GetUserDto {
username: string;
city: string;
image?: string;
}
But instead of
{
"username": "ExampleName",
"city": "ExampleTown"
}
it returns
{
"data": {
"username": "ExampleName",
"city": "ExampleTown"
}
}
What am I doing wrong?
Upvotes: 0
Views: 665
Reputation: 2620
Looks like you have some interceptor that transform your output, take a look here how it works, https://docs.nestjs.com/interceptors maybe you will be able to figure out in your project how it's.
Regards.
Upvotes: 2