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

Commit f913baa

Browse files
author
Hans Kristian Flaatten
committed
fix(near): return coordinates array with two (2) coordinates
1 parent 126fcc9 commit f913baa

File tree

2 files changed

+24
-4
lines changed

2 files changed

+24
-4
lines changed

index.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,16 @@ module.exports.prototype.customNear = field => (query, point) => {
7575
$near: {
7676
$geometry: {
7777
type: 'Point',
78-
coordinates: pointArr,
78+
coordinates: pointArr.splice(0, 2),
7979
},
8080
},
8181
};
8282

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

8686
if (!isNaN(min)) {
87-
query[field].$near.$minDistance = parseInt(pointArr[3], 10);
87+
query[field].$near.$minDistance = min;
8888
}
8989
}
9090
}

test.js

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,14 +77,34 @@ describe('customNear()', () => {
7777
$near: {
7878
$geometry: {
7979
type: 'Point',
80-
coordinates: point.split(',').splice(0, 3).map(parseFloat, 10),
80+
coordinates: point.split(',').splice(0, 2).map(parseFloat, 10),
8181
},
8282
$maxDistance: parseInt(point.split(',')[2], 10),
8383
},
8484
},
8585
});
8686
});
8787
});
88+
89+
it('returns $near query with max and min distance', () => {
90+
['0,1,2,4', '60.70908,10.37140,211.123,321.456'].forEach(point => {
91+
const q = {};
92+
93+
mqs.customNear('geojson')(q, point);
94+
assert.deepEqual(q, {
95+
geojson: {
96+
$near: {
97+
$geometry: {
98+
type: 'Point',
99+
coordinates: point.split(',').splice(0, 2).map(parseFloat, 10),
100+
},
101+
$maxDistance: parseInt(point.split(',')[2], 10),
102+
$minDistance: parseInt(point.split(',')[3], 10),
103+
},
104+
},
105+
});
106+
});
107+
});
88108
});
89109

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

0 commit comments

Comments
 (0)