Skip to content

Instantly share code, notes, and snippets.

@tarlepp
Last active October 22, 2015 04:32
Show Gist options
  • Save tarlepp/869165914c26d753dbd8 to your computer and use it in GitHub Desktop.
Save tarlepp/869165914c26d753dbd8 to your computer and use it in GitHub Desktop.
Generic count method
/**
* 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});
});
}
};
/**
* /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