mirror of
https://github.com/openstf/stf
synced 2025-10-04 10:19:30 +02:00
Normalize device data in one place.
This commit is contained in:
parent
ea13232f10
commit
5601fe2829
2 changed files with 16 additions and 18 deletions
|
@ -119,11 +119,7 @@ module.exports = function(options) {
|
||||||
return Promise.promisify(cursor.toArray, cursor)()
|
return Promise.promisify(cursor.toArray, cursor)()
|
||||||
.then(function(list) {
|
.then(function(list) {
|
||||||
list.forEach(function(device) {
|
list.forEach(function(device) {
|
||||||
datautil.applyData(device)
|
datautil.normalize(device, req.user)
|
||||||
datautil.applyOwner(device, req.user)
|
|
||||||
if (!device.present) {
|
|
||||||
device.owner = null
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
res.json({
|
res.json({
|
||||||
success: true
|
success: true
|
||||||
|
@ -145,11 +141,7 @@ module.exports = function(options) {
|
||||||
return Promise.promisify(cursor.toArray, cursor)()
|
return Promise.promisify(cursor.toArray, cursor)()
|
||||||
.then(function(list) {
|
.then(function(list) {
|
||||||
list.forEach(function(device) {
|
list.forEach(function(device) {
|
||||||
datautil.applyData(device)
|
datautil.normalize(device, req.user)
|
||||||
datautil.applyOwner(device, req.user)
|
|
||||||
if (!device.present) {
|
|
||||||
device.owner = null
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
res.json({
|
res.json({
|
||||||
success: true
|
success: true
|
||||||
|
@ -169,11 +161,7 @@ module.exports = function(options) {
|
||||||
dbapi.loadDevice(req.params.serial)
|
dbapi.loadDevice(req.params.serial)
|
||||||
.then(function(device) {
|
.then(function(device) {
|
||||||
if (device) {
|
if (device) {
|
||||||
datautil.applyData(device)
|
datautil.normalize(device, req.user)
|
||||||
datautil.applyOwner(device, req.user)
|
|
||||||
if (!device.present) {
|
|
||||||
device.owner = null
|
|
||||||
}
|
|
||||||
res.json({
|
res.json({
|
||||||
success: true
|
success: true
|
||||||
, device: device
|
, device: device
|
||||||
|
|
|
@ -10,7 +10,9 @@ var aliases = {
|
||||||
'KYY22': 'L02'
|
'KYY22': 'L02'
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.applyData = function(device) {
|
var datautil = module.exports = Object.create(null)
|
||||||
|
|
||||||
|
datautil.applyData = function(device) {
|
||||||
var model = device.model
|
var model = device.model
|
||||||
|
|
||||||
if (model) {
|
if (model) {
|
||||||
|
@ -50,11 +52,19 @@ module.exports.applyData = function(device) {
|
||||||
return device
|
return device
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.applyOwner = function(device, user) {
|
datautil.applyOwner = function(device, user) {
|
||||||
device.using = !!device.owner && device.owner.email === user.email
|
device.using = !!device.owner && device.owner.email === user.email
|
||||||
return device
|
return device
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports.middleware = function() {
|
datautil.normalize = function(device, user) {
|
||||||
|
datautil.applyData(device)
|
||||||
|
datautil.applyOwner(device, user)
|
||||||
|
if (!device.present) {
|
||||||
|
device.owner = null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
datautil.middleware = function() {
|
||||||
return express.static(pathutil.root('node_modules/stf-devices-db/data/small'))
|
return express.static(pathutil.root('node_modules/stf-devices-db/data/small'))
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue