1- var omit = require ( 'lodash/object/omit' ) ;
2- var isObject = require ( 'lodash/lang/isObject' ) ;
3- var util = require ( 'util' ) ;
4-
51/**
62 * Utility methods used in built-in blueprint actions.
73 *
@@ -14,51 +10,34 @@ module.exports = {
1410 * @param {Request } req
1511 * @return {WLCollection }
1612 */
17- parseModel : function ( req ) {
13+ parseModel : function ( req ) {
1814
1915 // Ensure a model can be deduced from the request options.
2016 var model = req . options . model || req . options . controller ;
21- if ( ! model ) throw new Error ( util . format ( 'No "model" specified in route options.' ) ) ;
17+ if ( ! model ) {
18+ throw new Error ( 'No "model" specified in route options.' ) ;
19+ }
2220
23- var Model = req . _sails . models [ model ] ;
24- if ( ! Model ) throw new Error ( util . format ( 'Invalid route option, "model".\nI don\'t know about any models named: `%s`' , model ) ) ;
21+ var Model = req . _sails . models [ model ] ;
22+ if ( ! Model ) {
23+ throw new Error ( 'Invalid route option, "model". No model named: ' + model ) ;
24+ }
2525
2626 return Model ;
2727 } ,
2828
29- /**
29+ /**
3030 * Parse `values` for a Waterline `create` or `update` from all
3131 * request parameters.
3232 *
3333 * @param {Request } req
3434 * @return {Object }
3535 */
36- parseValues : function ( req , model ) {
37- // Create data object (monolithic combination of all parameters)
38- // Omit the blacklisted params (like JSONP callback param, etc.)
39-
40- // Allow customizable blacklist for params NOT to include as values.
41- req . options . values = req . options . values || { } ;
42- req . options . values . blacklist = req . options . values . blacklist ;
36+ parseValues : function ( req , model ) {
4337
44- // Validate blacklist to provide a more helpful error msg.
45- var blacklist = req . options . values . blacklist ;
46- if ( blacklist && ! isArray ( blacklist ) ) {
47- throw new Error ( 'Invalid `req.options.values.blacklist`. Should be an array of strings (parameter names.)' ) ;
48- }
49-
50- // Get values using the model identity as resource identifier
51- var values = req . body . data . attributes || { } ;
38+ var values = req . body . data . attributes || { } ;
5239 values . id = req . allParams ( ) [ 'id' ] ;
5340
54- // Omit built-in runtime config (like query modifiers)
55- values = omit ( values , blacklist || [ ] ) ;
56-
57- // Omit any params w/ undefined values
58- values = omit ( values , function ( p ) {
59- if ( _ . isUndefined ( p ) ) return true ;
60- } ) ;
61-
6241 return values ;
6342 } ,
6443
@@ -69,7 +48,7 @@ module.exports = {
6948 * @param {Request } req
7049 * @return {Integer|String }
7150 */
72- parsePk : function ( req ) {
51+ parsePk : function ( req ) {
7352
7453 return req . options . id || ( req . options . where && req . options . where . id ) || req . allParams ( ) [ 'id' ] ;
7554 } ,
@@ -81,11 +60,12 @@ module.exports = {
8160 * @param {Request } req
8261 * @return {Integer|String }
8362 */
84- requirePk : function ( req ) {
85- var pk = module . exports . parsePk ( req ) ;
63+ requirePk : function ( req ) {
64+
65+ var pk = module . exports . parsePk ( req ) ;
8666
8767 // Validate the required `id` parameter
88- if ( ! pk ) {
68+ if ( ! pk ) {
8969
9070 var err = new Error (
9171 'No `id` parameter provided.' +
0 commit comments