Hello i am new to sails and would like some help with this. I am using sails with sails-mongo adapter and on my controllers when i am querying for data it returns okay and i can log the data fine but when i am trying to return the response back the object is empty. I have tried differen type of res like res.send()
res.status(200).send(
) res.json()
res.ok()
.
This is an example controller method:
class UserController {
/**
* Create User
* @param {*} req
* @param {*} res
* @returns {User|Error}
*/
static async create (req, res) {
var data = _.pick(req.body, ['username', 'password']);
Object.assign(data, { status: false });
try {
await User.create(data).fetch();
res.status(200).send('User created successfully.');
} catch (error) {
res.status(400).send(error.message);
}
}
/**
* Get all active users
* @param {*} req
* @param {*} res
* @returns {[]User|Error}
*/
static async getActive (req, res) {
try{
const users = await User.find({ status: true });
console.log(users);
return res.status(200).json(users);
} catch(error) {
res.status(500).send(error.message);
}
}
}
module.exports = {
create: UserController.create,
getActive: UserController.getActive,
}
I can see the return on log but the response is like this:
[
{}
]