From 76842ee7137eb9b3aa69573fa266b1e794eacf45 Mon Sep 17 00:00:00 2001 From: Nathan Leniz Date: Sat, 7 Mar 2015 04:51:00 +0900 Subject: [PATCH] Respond with 404 if no query found ref #151 --- controllers/story.js | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/controllers/story.js b/controllers/story.js index 5c32741461..3f2ea24bcc 100644 --- a/controllers/story.js +++ b/controllers/story.js @@ -100,7 +100,7 @@ exports.returnIndividualStory = function(req, res, next) { exports.getStories = function(req, res, next) { MongoClient.connect(secrets.db, function(err, database) { - db = database; + var db = database; debug('this is data', req.body.data.searchValue); db.collection('stories').find({ "$text": { @@ -127,19 +127,13 @@ exports.getStories = function(req, res, next) { } } }).toArray(function(err, items) { - debug('items', items); - return res.json(items); + if (items.length !== 0) { + debug('items found with full text', items); + return res.json(items); + } + return res.status(404); }); }); - //Story.find({'headline': new RegExp(req.body.data.searchValue, 'i')}, function (err, results) { - // if (err) { - // res.status(500); - // } - // debug('results are', results); - // - // res.json(results); - //}); - //}a); }; exports.upvote = function(req, res, next) {