Sails-beforeBlueprint-Policy

March 2, 2015 ยท View on GitHub

/**

*/

var actionUtil = require( 'sails/lib/hooks/blueprints/actionUtil' );

capitaliseFirstLetter = function ( string ) { return string.charAt( 0 ).toUpperCase() + string.slice( 1 ); };

module.exports = function ( req, res, next ) {

var Model = actionUtil.parseModel( req ); var blueprint = capitaliseFirstLetter( req.options.action ); // we actually enable this for all actions, not only blueprints

if ( typeof Model[ "controlBefore" + blueprint ] === "function" ) { var result = Model[ "controlBefore" + blueprint ]( req, res, next ); //next(); } else { sails.log.debug( 'Policy beforeBlueprint: Model "' + Model.identity + '" has no method controlBefore' + blueprint + '.' ); next(); }

};