mirror of
https://github.com/mainflux/mainflux.git
synced 2025-04-26 13:48:53 +08:00
Correct GET on single device
Signed-off-by: Drasko DRASKOVIC <drasko.draskovic@gmail.com>
This commit is contained in:
parent
8eee6f1bcf
commit
bd16fa2616
@ -11,9 +11,10 @@ var os = require('os');
|
||||
exports.createDevice = function(req, res, next) {
|
||||
|
||||
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 */
|
||||
devicesDb.insert(req.body, function(err, device) {
|
||||
devicesDb.save(req.body, function(err, device) {
|
||||
if (err)
|
||||
return next(err);
|
||||
|
||||
@ -21,8 +22,6 @@ exports.createDevice = function(req, res, next) {
|
||||
version: config.version
|
||||
}
|
||||
|
||||
console.log(signaturePayload);
|
||||
|
||||
var token = jwt.sign(signaturePayload, config.tokenSecret, {
|
||||
subject: 'Device Auth Token',
|
||||
issuer: req.headers.host,
|
||||
@ -32,7 +31,8 @@ exports.createDevice = function(req, res, next) {
|
||||
res.json({
|
||||
status: 200,
|
||||
message: 'Device created',
|
||||
token: token
|
||||
token: token,
|
||||
_id: device._id.toString()
|
||||
});
|
||||
});
|
||||
|
||||
@ -58,12 +58,15 @@ exports.getAllDevices = function(req, res, next) {
|
||||
/** getDevice() */
|
||||
exports.getDevice = function(req, res, next) {
|
||||
|
||||
console.log(req.params.device_id);
|
||||
devicesDb.findOne({_id: mongojs.ObjectId(req.params.device_id)}, function(err, device) {
|
||||
if (err)
|
||||
return next(err);
|
||||
|
||||
res.json(device);
|
||||
if (device) {
|
||||
res.json(device);
|
||||
} else {
|
||||
res.send("NOT FOUND");
|
||||
}
|
||||
return next();
|
||||
});
|
||||
}
|
||||
@ -87,6 +90,7 @@ exports.updateDevice = function(req, res, next) {
|
||||
|
||||
/** deleteDevice() */
|
||||
exports.deleteDevice = function(req, res, next) {
|
||||
|
||||
devicesDb.remove({
|
||||
_id: mongojs.ObjectId(req.params.device_id)
|
||||
}, function(err, device) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user