File tree Expand file tree Collapse file tree 2 files changed +26
-10
lines changed
Expand file tree Collapse file tree 2 files changed +26
-10
lines changed Original file line number Diff line number Diff line change 1- var HttpStatusError = require ( '../errors/HttpStatusError' ) ;
1+ var _ = require ( 'lodash' ) ,
2+ qs = require ( '../parsers/qs' ) ,
3+ HttpStatusError = require ( '../errors/HttpStatusError' ) ;
24
35module . exports = init ;
46
@@ -8,10 +10,16 @@ function init(model) {
810 ] ;
911
1012 function remove ( req , res , next ) {
11- var options = req . options || { } ;
12-
13- options . where = options . where || { } ;
14- options . where [ model . primaryKeyAttribute ] = req . params . id ;
13+ var keys = { } ,
14+ options = { } ;
15+
16+ keys . model = _ . keys ( model . primaryKeyAttributes ) ;
17+ keys . params = _ . keys ( req . params ) ;
18+ keys . filters = _ . intersection ( keys . model , keys . params ) ;
19+
20+ options . where = qs . filters ( _ . pick ( req . params , keys . filters ) )
21+
22+ options = _ . merge ( { } , options , req . options ) ;
1523
1624 model
1725 . findOne ( options )
Original file line number Diff line number Diff line change 1- var HttpStatusError = require ( '../errors/HttpStatusError' ) ,
1+ var _ = require ( 'lodash' ) ,
2+ qs = require ( '../parsers/qs' ) ,
3+ HttpStatusError = require ( '../errors/HttpStatusError' ) ,
24 plainTransform = require ( '../transforms/plain' ) ;
35
46module . exports = init ;
@@ -11,10 +13,16 @@ function init(model) {
1113
1214 function update ( req , res , next ) {
1315 var body = req . body ,
14- options = req . options || { } ;
15-
16- options . where = options . where || { } ;
17- options . where [ model . primaryKeyAttribute ] = req . params . id ;
16+ keys = { } ,
17+ options = { } ;
18+
19+ keys . model = _ . keys ( model . primaryKeyAttributes ) ;
20+ keys . params = _ . keys ( req . params ) ;
21+ keys . filters = _ . intersection ( keys . model , keys . params ) ;
22+
23+ options . where = qs . filters ( _ . pick ( req . params , keys . filters ) )
24+
25+ options = _ . merge ( { } , options , req . options ) ;
1826
1927 model
2028 . findOne ( options )
You can’t perform that action at this time.
0 commit comments