Created
September 5, 2014 11:16
-
-
Save RWOverdijk/f64d2c4e5bab4922e861 to your computer and use it in GitHub Desktop.
Count blueprint as featured in http://blog.spoonx.nl/sails-js-count-blueprint/
This file contains hidden or 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
var actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); | |
module.exports = function getCount (req, res) { | |
var Model = actionUtil.parseModel(req) | |
, criteria = actionUtil.parseCriteria(req); | |
Model.count(criteria, function(error, response) { | |
if (error) { | |
return res.serverError('database_error', error); | |
} | |
res.ok({count: response}); | |
}); | |
}; |
Can you please explain how to use it?
I'm using sails 0.10, and put this to api/blueprints folder of my project, i'we also make route as described in manual
'GET /count': {blueprint: 'count'},
but i dont get how to use it
@bigbn you must specify the name of the domain / controller , for example:
If you have a Model Foo.js and Controller FooController.js
config/routes.js
'GET /foo/count': {blueprint: 'count'}
You can call http://localhost:1337/foo/count
It Works!
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
👍 sweet, thank you!