Last active
October 22, 2015 04:32
-
-
Save tarlepp/869165914c26d753dbd8 to your computer and use it in GitHub Desktop.
Generic count method
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
/** | |
* api/services/BaseController.js | |
* | |
* Base controller for all sails.js controllers. This just contains some common code | |
* that every controller uses | |
*/ | |
'use strict'; | |
var actionUtil = require('sails/lib/hooks/blueprints/actionUtil'); | |
module.exports = { | |
/** | |
* Generic count action for controller. | |
* | |
* @param {Request} request | |
* @param {Response} response | |
*/ | |
count: function(request, response) { | |
var Model = actionUtil.parseModel(request); | |
Model | |
.count(actionUtil.parseCriteria(request)) | |
.exec(function found(error, count) { | |
response.json({count: count}); | |
}); | |
} | |
}; |
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
/** | |
* /api/controllers/ProjectController.js | |
* | |
* @description :: | |
* @docs :: http://sailsjs.org/#!documentation/controllers | |
*/ | |
'use strict'; | |
var _ = require("lodash"); | |
module.exports = _.merge(_.cloneDeep(require("../services/BaseController")), { | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment