aboutsummaryrefslogtreecommitdiff
path: root/src/web/DillerWeb.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/web/DillerWeb.js')
-rw-r--r--src/web/DillerWeb.js33
1 files changed, 33 insertions, 0 deletions
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();