Skip to content

Commit

Permalink
regexp needs to be enclosed with '/' now
Browse files Browse the repository at this point in the history
  • Loading branch information
ksato9700 committed Aug 8, 2016
1 parent b5d8ff5 commit 0ee0cc5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 17 deletions.
31 changes: 18 additions & 13 deletions lib/server.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 12 additions & 4 deletions src/server.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,19 @@ upload_content_data = (db, book_id, source, cb)->
gs.close (err)->
cb err

re_or_str = (src)->
if src[0] is '/' and src[-1..] is '/'
return {"$in": [new RegExp src[1...-1]]}
else
return src

app.route api_root + '/books'
.get (req, res)->
query = {}
if req.query.title
query['title'] = {"$in": [new RegExp req.query.title]}
query['title'] = re_or_str req.query.title
if req.query.author
query['authors.full_name'] = {"$in": [new RegExp req.query.author]}
query['authors.full_name'] = re_or_str req.query.author
if req.query.after
query['release_date'] = {"$gte": new Date (req.query.after)}
options =
Expand Down Expand Up @@ -238,7 +244,8 @@ app.route api_root + '/persons'
.get (req, res)->
query = {}
if req.query.name
query['full_name'] = {"$in": [new RegExp req.query.name]}
query['full_name'] = re_or_str req.query.name

app.my.persons.find query, {_id: 0}, (err, items)->
items.toArray (err, docs)->
if err
Expand All @@ -265,7 +272,8 @@ app.route api_root + '/workers'
.get (req, res)->
query = {}
if req.query.name
query.name = {"$in": [new RegExp req.query.name]}
query.name = re_or_str req.query.name

app.my.workers.find query, {_id: 0}, (err, items)->
items.toArray (err, docs)->
if err
Expand Down

0 comments on commit 0ee0cc5

Please sign in to comment.