Skip to content

Commit

Permalink
Fixed cleanQuery error. cleanQuery call moved after middleware initia…
Browse files Browse the repository at this point in the history
…lization to allow usage of populate and other options even when we are not using middleware.
  • Loading branch information
Enric León committed Jun 16, 2013
1 parent bac2407 commit 807f7ac
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/express-restify-mongoose.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,18 @@ var restify = function(app, model, options) {
var m = options.middleware;
options.middleware = [ m ];
}
options.middleware.unshift(cleanQuery);
} else {
options.middleware = [];
}
options.middleware.unshift(cleanQuery);

var queryOptions = {protected: ["skip", "limit", "sort", "populate"], current: {}};

var uri_items = util.format('%s%s/%ss', options.prefix, options.version, model.modelName);
var uri_item = util.format('%s%s/%ss/:id', options.prefix, options.version, model.modelName);

function cleanQuery(req, res, next) {
queryOptions.current = {};
queryOptions.current = {};
for(var key in req.query) {
if(!model.schema.paths.hasOwnProperty(key)) {
if(queryOptions.protected.indexOf(key) != -1) {
Expand Down Expand Up @@ -183,4 +183,4 @@ var restify = function(app, model, options) {
});
};

module.exports.serve = restify;
module.exports.serve = restify;

0 comments on commit 807f7ac

Please sign in to comment.