From 2173df227821aefe1cf9aee5d8165fa0a24961e9 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 1 Nov 2015 00:38:12 +0100 Subject: web: o Removing dupliated name and description fields from device. --- src/web/DillerWeb.js | 26 ++++++++++++---------- .../app/templates/device-edit-attribute.modal.html | 2 +- web/static/app/templates/device.html | 25 +++++++-------------- 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/web/DillerWeb.js b/src/web/DillerWeb.js index bcb15d4..3f1d107 100644 --- a/src/web/DillerWeb.js +++ b/src/web/DillerWeb.js @@ -20,8 +20,11 @@ function DillerWeb(tx, config) { function genericErrorHandler(res) { return function (data) { + if (typeof data === 'string') { + data = {message: data} + } log.warn('fail', data); - return res.status(500).json({message: 'fail', data: data}) + return res.status(500).json(data); } } @@ -58,25 +61,24 @@ function DillerWeb(tx, config) { var body = req.body; + var p; if (!body.attribute) { res.status(400).json({message: 'Required keys: "attribute" and "value".'}); } else if (body.attribute == 'name' || body.attribute == 'description') { var attributes = {}; attributes[body.attribute] = body.value; - return diller.updateDeviceAttributes(deviceId, attributes) - .then(function () { - return pg.batch([ - dao.deviceById(deviceId), - dao.devicePropertiesByDeviceId(deviceId)] - ); - }) - .then(function (data) { - res.json(deviceResponse(data)); - }, genericErrorHandler(res)); + p = diller.updateDeviceAttributes(deviceId, attributes); } else { - res.status(400).json({message: 'Unsupported attribute: ' + body.attribute}); + p = Promise.reject('Unsupported attribute: ' + body.attribute); } + + return p.then(function () { + return pg.batch([ + dao.deviceById(deviceId), + dao.devicePropertiesByDeviceId(deviceId)] + ); + }); }).then(function (data) { var device = data[0]; device.properties = data[1]; diff --git a/web/static/app/templates/device-edit-attribute.modal.html b/web/static/app/templates/device-edit-attribute.modal.html index 10314e5..2e57f2d 100644 --- a/web/static/app/templates/device-edit-attribute.modal.html +++ b/web/static/app/templates/device-edit-attribute.modal.html @@ -7,7 +7,7 @@