mirror of
https://github.com/DeviceFarmer/stf.git
synced 2026-04-18 08:53:23 +02:00
Normalize device data in one place.
This commit is contained in:
@@ -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'))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user