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

Commit 4dfef7a

Browse files
author
Hans Kristian Flaatten
committed
Add custom functions support
1 parent 01ae4fb commit 4dfef7a

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

src/index.litcoffee

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,14 @@
6969
7070
key = @alias[key] if @alias[key]
7171
72+
if @custom[key]
73+
@custom[key] res, val
74+
7275
If the value is empty we treat the query parameter as an
7376
[$exists](http://docs.mongodb.org/manual/reference/operator/query/exists/)
7477
operator.
7578

76-
if not val
79+
else if not val
7780
res[key] = $exists: true
7881
7982
Check for supported operators in `@ops`. This is configured when

test/suite.coffee

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,4 +149,23 @@ describe 'parse()', ->
149149
it 'should ingore multiple keys'
150150

151151
describe 'custom', ->
152+
it 'should enable built in bbox handler', ->
153+
qs = new MongoQS custom: bbox: 'geojson'
154+
assert.deepEqual qs.parse({bbox: '0,1,2,3'}), geojson:
155+
$geoWithin:
156+
$geometry:
157+
type: 'Polygon'
158+
coordinates: [[[0,1],[2,1],[2,3],[0,3],[0,1]]]
159+
160+
it 'should enable built in near handler', ->
161+
qs = new MongoQS custom: near: 'geojson'
162+
assert.deepEqual qs.parse({near: '0,1'}), geojson:
163+
$near:
164+
$geometry:
165+
type: 'Point'
166+
coordinates: [0,1]
167+
168+
it 'should enable build in after handler', ->
169+
qs = new MongoQS custom: after: 'endret'
170+
assert.deepEqual qs.parse({after: '2014-01-01'}), endret: $gte: '2014-01-01T00:00:00.000Z'
152171

0 commit comments

Comments
 (0)