Skip to content
This repository was archived by the owner on May 1, 2025. It is now read-only.

Commit 126fcc9

Browse files
author
Hans Kristian Flaatten
committed
fix(near): accept min and max parameters
1 parent 8c4e04f commit 126fcc9

File tree

2 files changed

+20
-4
lines changed

2 files changed

+20
-4
lines changed

index.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,9 @@ module.exports.prototype.customBBOX = (field) => (query, bbox) => {
6464
};
6565

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

6969
if (pointArr.length >= 2) {
70-
pointArr[0] = parseFloat(pointArr[0], 10);
71-
pointArr[1] = parseFloat(pointArr[1], 10);
72-
7370
if (!isNaN(pointArr.reduce((a, b) => a + b))) {
7471
const max = parseInt(pointArr[2], 10);
7572
const min = parseInt(pointArr[3], 10);

test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,25 @@ describe('customNear()', () => {
6666
});
6767
});
6868
});
69+
70+
it('returns $near query with max distance', () => {
71+
['0,1,2', '60.70908,10.37140,211.123'].forEach(point => {
72+
const q = {};
73+
74+
mqs.customNear('geojson')(q, point);
75+
assert.deepEqual(q, {
76+
geojson: {
77+
$near: {
78+
$geometry: {
79+
type: 'Point',
80+
coordinates: point.split(',').splice(0, 3).map(parseFloat, 10),
81+
},
82+
$maxDistance: parseInt(point.split(',')[2], 10),
83+
},
84+
},
85+
});
86+
});
87+
});
6988
});
7089

7190
describe('customAfter()', () => {

0 commit comments

Comments
 (0)