aboutsummaryrefslogtreecommitdiff
path: root/src/DillerDao.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/DillerDao.js')
-rw-r--r--src/DillerDao.js30
1 files changed, 14 insertions, 16 deletions
diff --git a/src/DillerDao.js b/src/DillerDao.js
index 2133dfc..a47f181 100644
--- a/src/DillerDao.js
+++ b/src/DillerDao.js
@@ -2,7 +2,7 @@ var _ = require('lodash');
function DillerDao(tx) {
- var deviceColumns = 'id, key, created_timestamp';
+ var deviceColumns = 'id, created_timestamp, key, name, description';
var propertyColumns = 'id, device, key, created_timestamp';
var valueColumns = 'property, timestamp, value_text, value_numeric';
@@ -27,27 +27,25 @@ function DillerDao(tx) {
}
function updateDevice(id, attributes) {
-
var values = [id];
var i = 2;
- var fields = _.map(attributes, function (value, name) {
- console.log('name', name, 'value', value, 'i', i);
- if (name == 'name') {
- values.push(value);
- return 'name = $' + i++;
- }
- });
+ var fields = _(attributes).chain()
+ .map(function (value, attribute) {
+ if (attribute == 'name' || attribute == 'description') {
+ values.push(value);
+ return attribute + ' = $' + i++;
+ }
+ })
+ .collect()
+ .join(', ')
+ .value();
if (fields.length == 0) {
- return; // TODO: return an empty promise;
+ return Promise.resolve({});
}
- fields = _.collect(fields);
-
- var x = 'UPDATE device SET ' + fields.join(', ') + ' WHERE id = $1';
- console.log('x', x);
- console.log('values', values);
- return tx.none(x, values);
+ var sql = 'UPDATE device SET ' + fields + ' WHERE id = $1';
+ return tx.none(sql, values);
}
// -------------------------------------------------------------------------------------------------------------------