Skip to content

Commit

Permalink
fix(near): return coordinates array with two (2) coordinates
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Kristian Flaatten committed Aug 6, 2016
1 parent 126fcc9 commit f913baa
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
6 changes: 3 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,16 +75,16 @@ module.exports.prototype.customNear = field => (query, point) => {
$near: {
$geometry: {
type: 'Point',
coordinates: pointArr,
coordinates: pointArr.splice(0, 2),
},
},
};

if (!isNaN(max)) {
query[field].$near.$maxDistance = parseInt(pointArr[2], 10);
query[field].$near.$maxDistance = max;

if (!isNaN(min)) {
query[field].$near.$minDistance = parseInt(pointArr[3], 10);
query[field].$near.$minDistance = min;
}
}
}
Expand Down
22 changes: 21 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,34 @@ describe('customNear()', () => {
$near: {
$geometry: {
type: 'Point',
coordinates: point.split(',').splice(0, 3).map(parseFloat, 10),
coordinates: point.split(',').splice(0, 2).map(parseFloat, 10),
},
$maxDistance: parseInt(point.split(',')[2], 10),
},
},
});
});
});

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

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

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

0 comments on commit f913baa

Please sign in to comment.