From 462c2a606572a09ccca73d0653710d5ee7e2855f Mon Sep 17 00:00:00 2001 From: andreagerino Date: Fri, 27 Nov 2015 21:05:57 +0100 Subject: [PATCH] ... --- routes/storage.js | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/routes/storage.js b/routes/storage.js index 67cf835..d5dd310 100644 --- a/routes/storage.js +++ b/routes/storage.js @@ -3,6 +3,8 @@ var router = express.Router(); var debug = require('debug')('Icarus:server'); var mongoClient = require('mongodb').MongoClient; +var objectID = mongoClient.objectId; + var assert = assert = require('assert'); // Connection URL @@ -20,7 +22,6 @@ mongoClient.connect(mongoUrl, function(err, db) { router.get('/:resource_id', function(req, res, next) { - var _id = req.params.resource_id; mongoClient.connect(mongoUrl, function(err, db) { if(err!=null){ @@ -32,6 +33,7 @@ router.get('/:resource_id', function(req, res, next) { var collection = db.collection('resources'); + var _id = new objectID(req.params.resource_id); collection.find({"_id":_id}).limit(1).next(function(err, doc){ if(err!=null){ @@ -43,7 +45,7 @@ router.get('/:resource_id', function(req, res, next) { if(doc==undefined){ - res.sendStatus(400); + res.sendStatus(404); }else{ -- 2.18.1