From 7d1ec560872a235dce988fab785802bb0133a505 Mon Sep 17 00:00:00 2001 From: andreagerino Date: Fri, 27 Nov 2015 21:02:07 +0100 Subject: [PATCH] ... --- routes/storage.js | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/routes/storage.js b/routes/storage.js index d2d2661..67cf835 100644 --- a/routes/storage.js +++ b/routes/storage.js @@ -20,7 +20,44 @@ mongoClient.connect(mongoUrl, function(err, db) { router.get('/:resource_id', function(req, res, next) { - res.sendStatus(200); + var _id = req.params.resource_id; + mongoClient.connect(mongoUrl, function(err, db) { + + if(err!=null){ + + debug(err); + next(err); + + }else{ + + var collection = db.collection('resources'); + + collection.find({"_id":_id}).limit(1).next(function(err, doc){ + + if(err!=null){ + + debug(err); + next(err); + + }else{ + + if(doc==undefined){ + + res.sendStatus(400); + + }else{ + + res.send(doc); + + } + + } + + }); + + } + + }); }); -- 2.18.1