From f7ff8a837bed336a14aa0442ed8286f3ef78f577 Mon Sep 17 00:00:00 2001 From: Trygve Laugstøl Date: Sun, 1 Nov 2015 01:06:40 +0100 Subject: core: o Adding updates of device property's name and description. web: o Ading editing of property name and description. --- src/web/DillerWeb.js | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'src/web/DillerWeb.js') diff --git a/src/web/DillerWeb.js b/src/web/DillerWeb.js index 3f1d107..03daca7 100644 --- a/src/web/DillerWeb.js +++ b/src/web/DillerWeb.js @@ -98,6 +98,37 @@ function DillerWeb(tx, config) { }); } + function patchProperty(req, res) { + tx(function (pg, dao, diller) { + var propertyId = req.params.propertyId; + + 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; + + p = diller.updatePropertyAttributes(propertyId, attributes); + } else { + p = Promise.reject('Unsupported attribute: ' + body.attribute); + } + + return p.then(function (property) { + return pg.batch([ + dao.deviceById(property.device), + dao.devicePropertiesByDeviceId(property.device)] + ); + }); + }).then(function (data) { + var device = data[0]; + device.properties = data[1]; + res.json({device: device}); + }, genericErrorHandler(res)); + } + function getIndex(req, res) { var baseUrl = (req.headers['trygvis-prefix'] || '').replace(/\/$/, ''); res.render('index', {baseUrl: baseUrl + '/'}); @@ -143,7 +174,9 @@ function DillerWeb(tx, config) { addApi('getDevices', 'get', '/device', getDevices); addApi('getDevice', 'get', '/device/:deviceId', getDevice); addApi('patchDevice', 'patch', '/device/:deviceId', patchDevice); + addApi('getValues', 'get', '/property/:propertyId/values', getValues); + addApi('patchProperty', 'patch', '/property/:propertyId/values', patchProperty); var templates = express.Router(); -- cgit v1.2.3