Skip to content

Commit

Permalink
Merge pull request #1030 from ignacionar/#918
Browse files Browse the repository at this point in the history
#918 Return correct device name from API
  • Loading branch information
dhreben authored Oct 8, 2024
2 parents 259b6df + d8d0ce7 commit 6e44541
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/units/api/controllers/devices.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ const wirerouter = require('../../../wire/router')
function filterGenericDevices(req, res, devices) {
apiutil.respond(res, 200, 'Devices Information', {
devices: devices.map(function(device) {
return apiutil.filterDevice(req, device)
const filteredDevice = apiutil.filterDevice(req, device)
filteredDevice.name = device.model
return filteredDevice
})
})
}
Expand Down Expand Up @@ -221,6 +223,7 @@ function getDeviceBySerial(req, res) {

dbapi.loadDevice(req.user.groups.subscribed, serial)
.then(function(cursor) {
const deviceName = cursor._responses[0].r[0].model
cursor.next(function(err, device) {
if (err) {
return res.status(404).json({
Expand All @@ -230,6 +233,8 @@ function getDeviceBySerial(req, res) {
}
let responseDevice = apiutil.publishDevice(device, req.user)

responseDevice.name = deviceName

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

0 comments on commit 6e44541

Please sign in to comment.