1
0
mirror of https://github.com/mainflux/mainflux.git synced 2025-04-27 13:48:49 +08:00

Correct GET on single device

Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
Drasko DRASKOVIC 2015-12-08 02:38:01 +01:00
parent 8eee6f1bcf
commit bd16fa2616

View File

@ -11,9 +11,10 @@ var os = require('os');
exports.createDevice = function(req, res, next) { exports.createDevice = function(req, res, next) {
console.log("req.headers['x-auth-token'] = ", req.headers['x-auth-token']); console.log("req.headers['x-auth-token'] = ", req.headers['x-auth-token']);
console.log("req.headers['content-type'] = ", req.headers['content-type']);
/** Save the device and check for errors */ /** Save the device and check for errors */
devicesDb.insert(req.body, function(err, device) { devicesDb.save(req.body, function(err, device) {
if (err) if (err)
return next(err); return next(err);
@ -21,8 +22,6 @@ exports.createDevice = function(req, res, next) {
version: config.version version: config.version
} }
console.log(signaturePayload);
var token = jwt.sign(signaturePayload, config.tokenSecret, { var token = jwt.sign(signaturePayload, config.tokenSecret, {
subject: 'Device Auth Token', subject: 'Device Auth Token',
issuer: req.headers.host, issuer: req.headers.host,
@ -32,7 +31,8 @@ exports.createDevice = function(req, res, next) {
res.json({ res.json({
status: 200, status: 200,
message: 'Device created', message: 'Device created',
token: token token: token,
_id: device._id.toString()
}); });
}); });
@ -58,12 +58,15 @@ exports.getAllDevices = function(req, res, next) {
/** getDevice() */ /** getDevice() */
exports.getDevice = function(req, res, next) { exports.getDevice = function(req, res, next) {
console.log(req.params.device_id);
devicesDb.findOne({_id: mongojs.ObjectId(req.params.device_id)}, function(err, device) { devicesDb.findOne({_id: mongojs.ObjectId(req.params.device_id)}, function(err, device) {
if (err) if (err)
return next(err); return next(err);
res.json(device); if (device) {
res.json(device);
} else {
res.send("NOT FOUND");
}
return next(); return next();
}); });
} }
@ -87,6 +90,7 @@ exports.updateDevice = function(req, res, next) {
/** deleteDevice() */ /** deleteDevice() */
exports.deleteDevice = function(req, res, next) { exports.deleteDevice = function(req, res, next) {
devicesDb.remove({ devicesDb.remove({
_id: mongojs.ObjectId(req.params.device_id) _id: mongojs.ObjectId(req.params.device_id)
}, function(err, device) { }, function(err, device) {