I recently embarked on a Ts.ED project utilizing TypeORM and Swagger to interact with my database. I've set up a UserController.ts
file and a UserService.ts
file. Within the service file, there's an async function that retrieves all users from my database.
async find(): Promise<Users[]> {
const users = await this.connection.manager.find(Users);
return users
}
In my controller file, I invoke the service function, find
, so its response appears on swagger ui.
@Get('/')
@Returns(200, Array).Of(Users)
async findAll(): Promise<Users[]> {
const users = await this.usersService.find()
console.log('user',users)
return users
}
Interestingly, while the console.log call shows everything properly, the response body in swagger ui only displays
[
{},
{},
{}...
]
It presents the correct number of objects but they are empty.
However, if I modify the controller function to
@Get('/')
//@Returns(200, Array).Of(Users)
async findAll(): Promise<Users> {
const users = await this.usersService.find()
console.log('user',users)
return users[0]
}
the object is displayed accurately in swagger ui, including all properties.
Any thoughts on why the array's objects appear empty?