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
|
@ -10,7 +10,9 @@ var aliases = {
|
|||
'KYY22': 'L02'
|
||||
}
|
||||
|
||||
module.exports.applyData = function(device) {
|
||||
var datautil = module.exports = Object.create(null)
|
||||
|
||||
datautil.applyData = function(device) {
|
||||
var model = device.model
|
||||
|
||||
if (model) {
|
||||
|
@ -50,11 +52,19 @@ module.exports.applyData = function(device) {
|
|||
return device
|
||||
}
|
||||
|
||||
module.exports.applyOwner = function(device, user) {
|
||||
datautil.applyOwner = function(device, user) {
|
||||
device.using = !!device.owner && device.owner.email === user.email
|
||||
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'))
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue