Skip to content

Commit

Permalink
Fix eslint errors
Browse files Browse the repository at this point in the history
  • Loading branch information
vbanthia committed Jul 22, 2016
1 parent a875d85 commit b60cb6e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 35 deletions.
14 changes: 9 additions & 5 deletions lib/units/api/controllers/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ function getDevices(req, res) {

list.forEach(function(device) {
datautil.normalize(device, req.user)
var responseDevice = device

if (fields) {
device = _.pick(device, fields.split(','))
responseDevice = _.pick(device, fields.split(','))
}
deviceList.push(device)
deviceList.push(responseDevice)
})

res.json({
Expand Down Expand Up @@ -57,13 +59,15 @@ function getDeviceBySerial(req, res) {
}

datautil.normalize(device, req.user)
if(fields) {
device = _.pick(device, fields.split(','))
var responseDevice = device

if (fields) {
responseDevice = _.pick(device, fields.split(','))
}

res.json({
success: true
, device: device
, device: responseDevice
})
})
.catch(function(err) {
Expand Down
26 changes: 13 additions & 13 deletions lib/units/api/controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,11 @@ function getUserDevices(req, res) {

list.forEach(function(device) {
datautil.normalize(device, req.user)
var responseDevice = device
if (fields) {
device = _.pick(device, fields.split(','))
responseDevice = _.pick(device, fields.split(','))
}
deviceList.push(device)
deviceList.push(responseDevice)
})

res.json({
Expand Down Expand Up @@ -84,13 +85,14 @@ function getUserDeviceBySerial(req, res) {
})
}

if(fields) {
device = _.pick(device, fields.split(','))
var responseDevice = device
if (fields) {
responseDevice = _.pick(device, fields.split(','))
}

res.json({
success: true
, device: device
, device: responseDevice
})
})
.catch(function(err) {
Expand Down Expand Up @@ -158,9 +160,9 @@ function addUserDevice(req, res) {
)
, timeout
, wireutil.toDeviceRequirements({
'serial': {
'value': serial
, 'match': 'exact'
serial: {
value: serial
, match: 'exact'
}
})
)
Expand Down Expand Up @@ -193,7 +195,6 @@ function deleteUserDeviceBySerial(req, res) {
success: false
, description: 'You cannot release this device. Not owned by you'
})

}

// Timer will be called if no JoinGroupMessage is received till 5 seconds
Expand Down Expand Up @@ -226,9 +227,9 @@ function deleteUserDeviceBySerial(req, res) {
, wireutil.envelope(
new wire.UngroupMessage(
wireutil.toDeviceRequirements({
'serial': {
'value': serial
, 'match': 'exact'
serial: {
value: serial
, match: 'exact'
}
})
)
Expand Down Expand Up @@ -314,7 +315,6 @@ function remoteDisconnectUserDeviceBySerial(req, res) {

dbapi.loadDevice(serial)
.then(function(device) {

if (!device) {
return res.status(404).json({
success: false
Expand Down
9 changes: 5 additions & 4 deletions lib/units/api/helpers/securityHandlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ module.exports = {
function accessTokenAuth(req, res, next) {
if (req.headers.authorization) {
var authHeader = req.headers.authorization.split(' ')
, format = authHeader[0]
, tokenId = authHeader[1]
var format = authHeader[0]
var tokenId = authHeader[1]

if (format !== 'Bearer') {
return res.status(401).json({
Expand All @@ -42,7 +42,7 @@ function accessTokenAuth(req, res, next) {
}

var jwt = token.jwt
, data = jwtutil.decode(jwt, req.options.secret)
var data = jwtutil.decode(jwt, req.options.secret)

if (!data) {
return res.status(500).json({
Expand All @@ -54,7 +54,8 @@ function accessTokenAuth(req, res, next) {
if (user) {
req.user = user
next()
} else {
}
else {
return res.status(500).json({
success: false
})
Expand Down
18 changes: 9 additions & 9 deletions lib/units/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ var wireutil = require('../../wire/util')

module.exports = function(options) {
var log = logger.createLogger('api')
, app = express()
, server = http.createServer(app)
, channelRouter = new events.EventEmitter()
var app = express()
var server = http.createServer(app)
var channelRouter = new events.EventEmitter()

var push = zmqutil.socket('push')
Promise.map(options.endpoints.push, function(endpoint) {
Expand All @@ -30,7 +30,7 @@ module.exports = function(options) {
})
})
})
.catch(function(err) {w
.catch(function(err) {
log.fatal('Unable to connect to push endpoint', err)
lifecycle.fatal()
})
Expand Down Expand Up @@ -65,22 +65,22 @@ module.exports = function(options) {
var config = {
appRoot: __dirname
, swaggerFile: path.resolve(__dirname, 'swagger', 'api_v1.yaml')
};
}

SwaggerExpress.create(config, function(err, swaggerExpress) {
if (err) {
throw err
}
swaggerExpress.register(app);
swaggerExpress.register(app)
})

// Adding options in request, so that swagger controller
// can use it.
app.use(function(req, res, next) {
var reqOptions = _.merge(options, {
'push': push
, 'sub': sub
, 'channelRouter': channelRouter
push: push
, sub: sub
, channelRouter: channelRouter
})

req.options = reqOptions
Expand Down
4 changes: 3 additions & 1 deletion lib/util/datautil.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,9 @@ datautil.applyOwner = function(device, user) {
// Only owner can see this information
datautil.applyOwnerOnlyInfo = function(device, user) {
if (device.owner && device.owner.email === user.email) {
} else {
// No-op
}
else {
device.remoteConnect = false
device.remoteConnectUrl = null
}
Expand Down
11 changes: 9 additions & 2 deletions lib/util/deviceutil.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,16 @@ var log = logger.createLogger('util:deviceutil')
var deviceutil = module.exports = Object.create(null)

deviceutil.isOwnedByUser = function(device, user) {
return device.present && device.ready && device.owner && device.owner.email === user.email && device.using
return device.present &&
device.ready &&
device.owner &&
device.owner.email === user.email &&
device.using
}

deviceutil.isAddable = function(device, user) {
return device.present && device.ready && !device.using && !device.owner
return device.present &&
device.ready &&
!device.using &&
!device.owner
}
2 changes: 1 addition & 1 deletion res/app/components/stf/device/device-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ module.exports = function DeviceServiceFactory($http, socket, EnhanceDeviceServi
})

oboe('/api/v1/user/devices')
.node('devices[*]', function (device) {
.node('devices[*]', function(device) {
tracker.add(device)
})

Expand Down

0 comments on commit b60cb6e

Please sign in to comment.