mirror of
https://github.com/openstf/stf
synced 2025-10-05 19:42:01 +02:00
Fix eslint errors
This commit is contained in:
parent
a875d85c46
commit
b60cb6ef6a
7 changed files with 49 additions and 35 deletions
|
@ -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({
|
||||
|
@ -57,13 +59,15 @@ function getDeviceBySerial(req, res) {
|
|||
}
|
||||
|
||||
datautil.normalize(device, req.user)
|
||||
var responseDevice = device
|
||||
|
||||
if (fields) {
|
||||
device = _.pick(device, fields.split(','))
|
||||
responseDevice = _.pick(device, fields.split(','))
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true
|
||||
, device: device
|
||||
, device: responseDevice
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
|
|
|
@ -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({
|
||||
|
@ -84,13 +85,14 @@ function getUserDeviceBySerial(req, res) {
|
|||
})
|
||||
}
|
||||
|
||||
var responseDevice = device
|
||||
if (fields) {
|
||||
device = _.pick(device, fields.split(','))
|
||||
responseDevice = _.pick(device, fields.split(','))
|
||||
}
|
||||
|
||||
res.json({
|
||||
success: true
|
||||
, device: device
|
||||
, device: responseDevice
|
||||
})
|
||||
})
|
||||
.catch(function(err) {
|
||||
|
@ -158,9 +160,9 @@ function addUserDevice(req, res) {
|
|||
)
|
||||
, timeout
|
||||
, wireutil.toDeviceRequirements({
|
||||
'serial': {
|
||||
'value': serial
|
||||
, 'match': 'exact'
|
||||
serial: {
|
||||
value: serial
|
||||
, match: 'exact'
|
||||
}
|
||||
})
|
||||
)
|
||||
|
@ -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
|
||||
|
@ -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'
|
||||
}
|
||||
})
|
||||
)
|
||||
|
@ -314,7 +315,6 @@ function remoteDisconnectUserDeviceBySerial(req, res) {
|
|||
|
||||
dbapi.loadDevice(serial)
|
||||
.then(function(device) {
|
||||
|
||||
if (!device) {
|
||||
return res.status(404).json({
|
||||
success: false
|
||||
|
|
|
@ -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({
|
||||
|
@ -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({
|
||||
|
@ -54,7 +54,8 @@ function accessTokenAuth(req, res, next) {
|
|||
if (user) {
|
||||
req.user = user
|
||||
next()
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
return res.status(500).json({
|
||||
success: false
|
||||
})
|
||||
|
|
|
@ -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) {
|
||||
|
@ -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()
|
||||
})
|
||||
|
@ -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
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue