Created
May 13, 2014 17:44
-
-
Save ofridagan/432e81e0f534b0cfcf13 to your computer and use it in GitHub Desktop.
Sails.js find action that returns a format for Ember
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
find: (req, res, next) -> | |
id = req.param 'id' | |
return next() if isShourtCut id | |
if id | |
User.findOne id, (err, user) -> | |
return res.notFound() if user == undefined | |
return next err if err | |
res.json user | |
else | |
where = req.param 'where' | |
where = JSON.parse where if _.isString where | |
options = | |
limit: req.param 'limit' || undefined | |
skip: req.param 'skip' || undefined | |
sort: req.param 'sort' || undefined | |
where: req.param 'where' || undefined | |
User.find options, (err, users) -> | |
return res.notFound() if users == undefined | |
return next err if err | |
res.json {users} | |
isShourtCut = (id) -> _.contains ["find", "create", "update", "destroy"], id |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment