Modify APIs from Aysnc -> Sync using timeout

This commit is contained in:
Vishal Banthia
2015-12-14 14:02:20 +09:00
parent d67d06a19f
commit a6266931ad
10 changed files with 354 additions and 239 deletions

View File

@@ -49,24 +49,22 @@ function getDeviceBySerial(req, res) {
dbapi.loadDevice(serial)
.then(function(device) {
if (device) {
datautil.normalize(device, req.user)
if(fields) {
device = _.pick(device, fields.split(','))
}
res.json({
success: true
, device: device
})
}
else {
res.status(404).json({
if (!device) {
return res.status(404).json({
success: false
, description: 'Device not found'
})
}
datautil.normalize(device, req.user)
if(fields) {
device = _.pick(device, fields.split(','))
}
res.json({
success: true
, device: device
})
})
.catch(function(err) {
log.error('Failed to load device "%s": ', req.params.serial, err.stack)