Reputation: 920
I get this error when I 'GET' this controller action:
TypeError: Cannot read property 'then' of undefined
Code:
allUsers: function (req, res) {
Admin.find({ id: req.adminId }, function (err, admin) {
console.log(admin);
})
.then(function onSuccess(admin) {
return User.find(function (err, users) {
res.json(users);
});
})
.catch(function onError(res) {
return res.status(401).send();
});
}
Any thoughts?
Upvotes: 0
Views: 359
Reputation: 508
Seems like you are trying to mix callback and promise style here. What happens if you delete the part:
, function (err, admin) {
console.log(admin);
}
According to Sails.js ORM documentation, the promise style find
is crafted like this:
Zookeeper.find()
.then(function (zookeepers) {...})
.catch(function (err) {...});
Upvotes: 1