Skip to content

Commit

Permalink
fix(near): accept min and max parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Kristian Flaatten committed Aug 6, 2016
1 parent 8c4e04f commit 126fcc9
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
5 changes: 1 addition & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,9 @@ module.exports.prototype.customBBOX = (field) => (query, bbox) => {
};

module.exports.prototype.customNear = field => (query, point) => {
const pointArr = point.split(',');
const pointArr = point.split(',').map(p => parseFloat(p, 10));

if (pointArr.length >= 2) {
pointArr[0] = parseFloat(pointArr[0], 10);
pointArr[1] = parseFloat(pointArr[1], 10);

if (!isNaN(pointArr.reduce((a, b) => a + b))) {
const max = parseInt(pointArr[2], 10);
const min = parseInt(pointArr[3], 10);
Expand Down
19 changes: 19 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,25 @@ describe('customNear()', () => {
});
});
});

it('returns $near query with max distance', () => {
['0,1,2', '60.70908,10.37140,211.123'].forEach(point => {
const q = {};

mqs.customNear('geojson')(q, point);
assert.deepEqual(q, {
geojson: {
$near: {
$geometry: {
type: 'Point',
coordinates: point.split(',').splice(0, 3).map(parseFloat, 10),
},
$maxDistance: parseInt(point.split(',')[2], 10),
},
},
});
});
});
});

describe('customAfter()', () => {
Expand Down

0 comments on commit 126fcc9

Please sign in to comment.