aboutsummaryrefslogtreecommitdiff
path: root/src/web
diff options
context:
space:
mode:
authorTrygve Laugstøl <trygvis@inamo.no>2015-11-01 15:28:40 +0100
committerTrygve Laugstøl <trygvis@inamo.no>2015-11-01 15:28:40 +0100
commit85474565b0a0d92a09fecb14e8bc0afaad7fbc64 (patch)
tree66fc12f1fdfcd19e4a5d0fc01666a191bc3cdcb0 /src/web
parentf7ff8a837bed336a14aa0442ed8286f3ef78f577 (diff)
downloaddiller-server-85474565b0a0d92a09fecb14e8bc0afaad7fbc64.tar.gz
diller-server-85474565b0a0d92a09fecb14e8bc0afaad7fbc64.tar.bz2
diller-server-85474565b0a0d92a09fecb14e8bc0afaad7fbc64.tar.xz
diller-server-85474565b0a0d92a09fecb14e8bc0afaad7fbc64.zip
misc:
o Playing around with type annotations.
Diffstat (limited to 'src/web')
-rw-r--r--src/web/DillerWeb.js49
1 files changed, 41 insertions, 8 deletions
diff --git a/src/web/DillerWeb.js b/src/web/DillerWeb.js
index 03daca7..42aa7bf 100644
--- a/src/web/DillerWeb.js
+++ b/src/web/DillerWeb.js
@@ -3,13 +3,12 @@ var bodyParser = require('body-parser');
var _ = require('lodash');
var di = require('di');
-var DillerConfig = require('../DillerConfig');
-var DillerTx = require('../DillerTx');
+var _DillerConfig = require('../DillerConfig');
+var _DillerTx = require('../DillerTx');
/**
- * @param tx DillerTx
- * @param config DillerConfig
- * @returns {{init: init, listen: listen, generateRpc: generateRpc}}
+ * @param {function(function(PgTx, DillerDao, Diller))} tx
+ * @param {DillerConfig} config
* @constructor
*/
function DillerWeb(tx, config) {
@@ -18,14 +17,17 @@ function DillerWeb(tx, config) {
var calls = [];
var app;
+ /**
+ * @param {HttpRes} res
+ */
function genericErrorHandler(res) {
return function (data) {
if (typeof data === 'string') {
- data = {message: data}
+ data = {message: data};
}
log.warn('fail', data);
return res.status(500).json(data);
- }
+ };
}
function deviceResponse(data) {
@@ -34,6 +36,10 @@ function DillerWeb(tx, config) {
return {device: device};
}
+ /**
+ * @param {HttpReq} req
+ * @param {HttpRes} res
+ */
function getDevices(req, res) {
tx(function (pg, dao) {
return dao.devices();
@@ -42,6 +48,10 @@ function DillerWeb(tx, config) {
}, genericErrorHandler(res));
}
+ /**
+ * @param {HttpReq} req
+ * @param {HttpRes} res
+ */
function getDevice(req, res) {
tx(function (pg, dao) {
var deviceId = req.params.deviceId;
@@ -55,6 +65,10 @@ function DillerWeb(tx, config) {
}, genericErrorHandler(res));
}
+ /**
+ * @param {HttpReq} req
+ * @param {HttpRes} res
+ */
function patchDevice(req, res) {
tx(function (pg, dao, diller) {
var deviceId = req.params.deviceId;
@@ -86,6 +100,10 @@ function DillerWeb(tx, config) {
}, genericErrorHandler(res));
}
+ /**
+ * @param {HttpReq} req
+ * @param {HttpRes} res
+ */
function getValues(req, res) {
tx(function (tx, dao) {
var propertyId = req.params.propertyId;
@@ -98,6 +116,10 @@ function DillerWeb(tx, config) {
});
}
+ /**
+ * @param {HttpReq} req
+ * @param {HttpRes} res
+ */
function patchProperty(req, res) {
tx(function (pg, dao, diller) {
var propertyId = req.params.propertyId;
@@ -129,6 +151,10 @@ function DillerWeb(tx, config) {
}, genericErrorHandler(res));
}
+ /**
+ * @param {HttpReq} req
+ * @param {HttpRes} res
+ */
function getIndex(req, res) {
var baseUrl = (req.headers['trygvis-prefix'] || '').replace(/\/$/, '');
res.render('index', {baseUrl: baseUrl + '/'});
@@ -142,6 +168,12 @@ function DillerWeb(tx, config) {
var api = express.Router();
+ /**
+ * @param name
+ * @param method
+ * @param path
+ * @param {function(HttpReq, HttpRes)} callback
+ */
function addApi(name, method, path, callback) {
api[method](path, callback);
var layer = _.last(api.stack);
@@ -192,6 +224,7 @@ function DillerWeb(tx, config) {
}
function listen() {
+ log.info('Starting HTTP listener on ' + config.httpPort);
app.listen(config.httpPort);
}
@@ -260,6 +293,6 @@ function DillerWeb(tx, config) {
}
}
-di.annotate(DillerWeb, new di.Inject(DillerTx, DillerConfig));
+di.annotate(DillerWeb, new di.Inject(_DillerTx, _DillerConfig));
module.exports = DillerWeb;