Skip to content

Commit

Permalink
Add custom functions support
Browse files Browse the repository at this point in the history
  • Loading branch information
Hans Kristian Flaatten committed Sep 22, 2014
1 parent 01ae4fb commit 4dfef7a
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.litcoffee
Original file line number Diff line number Diff line change
Expand Up @@ -69,11 +69,14 @@
key = @alias[key] if @alias[key]
if @custom[key]
@custom[key] res, val
If the value is empty we treat the query parameter as an
[$exists](http://docs.mongodb.org/manual/reference/operator/query/exists/)
operator.

if not val
else if not val
res[key] = $exists: true
Check for supported operators in `@ops`. This is configured when
Expand Down
19 changes: 19 additions & 0 deletions test/suite.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -149,4 +149,23 @@ describe 'parse()', ->
it 'should ingore multiple keys'

describe 'custom', ->
it 'should enable built in bbox handler', ->
qs = new MongoQS custom: bbox: 'geojson'
assert.deepEqual qs.parse({bbox: '0,1,2,3'}), geojson:
$geoWithin:
$geometry:
type: 'Polygon'
coordinates: [[[0,1],[2,1],[2,3],[0,3],[0,1]]]

it 'should enable built in near handler', ->
qs = new MongoQS custom: near: 'geojson'
assert.deepEqual qs.parse({near: '0,1'}), geojson:
$near:
$geometry:
type: 'Point'
coordinates: [0,1]

it 'should enable build in after handler', ->
qs = new MongoQS custom: after: 'endret'
assert.deepEqual qs.parse({after: '2014-01-01'}), endret: $gte: '2014-01-01T00:00:00.000Z'

0 comments on commit 4dfef7a

Please sign in to comment.