Browse Source

Merge branch 'master' into multiple_suggesters

msv2
Harish Krishna 10 years ago
parent
commit
a0ed108d71
  1. 2
      query/reverse.js
  2. 6
      sanitiser/_size.js
  3. 10
      sanitiser/reverse.js
  4. 10
      test/unit/query/reverse.js

2
query/reverse.js

@ -9,7 +9,7 @@ function generate( params ){
lon: params.lon
};
return queries.distance( centroid, { size: 1 } );
return queries.distance( centroid, { size: params.size || 1 } );
}
module.exports = generate;

6
sanitiser/_size.js

@ -1,9 +1,11 @@
// validate inputs, convert types and apply defaults
function sanitize( req ){
function sanitize( req, default_size){
var clean = req.clean || {};
var params= req.query;
var default_size = default_size || 10;
// ensure the input params are a valid object
if( Object.prototype.toString.call( params ) !== '[object Object]' ){
params = {};
@ -14,7 +16,7 @@ function sanitize( req ){
if( !isNaN( size ) ){
clean.size = Math.min( Math.max( size, 1 ), 40 ); // max
} else {
clean.size = 10; // default
clean.size = default_size; // default
}
req.clean = clean;

10
sanitiser/reverse.js

@ -2,8 +2,12 @@
var logger = require('../src/logger'),
_sanitize = require('../sanitiser/_sanitize'),
sanitiser = {
latlonzoom: require('../sanitiser/_latlonzoom')
};
latlonzoom: require('../sanitiser/_latlonzoom'),
size: function( req ) {
var size = require('../sanitiser/_size');
return size(req, 1);
}
};
var sanitize = function(req, cb) { _sanitize(req, sanitiser, cb); }
@ -20,4 +24,4 @@ module.exports.middleware = function( req, res, next ){
req.clean = clean;
next();
});
};
};

10
test/unit/query/reverse.js

@ -58,6 +58,16 @@ module.exports.tests.query = function(test, common) {
};
t.deepEqual(query, expected, 'valid reverse query');
// test different sizes
var sizes = [1,2,10,undefined,null];
sizes.forEach( function(size) {
query = generate({
lat: 29.49136, lon: -82.50622, size: size
});
expected.size = size ? size : 1;
t.deepEqual(query, expected, 'valid reverse query for size: '+ size);
});
t.end();
});
};

Loading…
Cancel
Save