mdot_server/lib/mdot/apiv2.js
Martin Donnelly de8af028e5 Updated to use PGSql backend
Before convertion of graph object to use AMCharts..
2016-08-11 15:34:52 +01:00

52 lines
1.1 KiB
JavaScript

'use strict';
var logger = require('log4js').getLogger();
var mdot = require('./mdot.js');
var db = require('../server/db-connector').dbConnection;
var dbMdot = require('../server/db-mdot')(db);
module.exports = function(app) {
var express = require('express');
var mdotRouter = express.Router();
mdotRouter.get('/:id', function(req, res) {
console.log(req.headers);
var data = {};
logger.debug('mDot-GetData');
if (!req.params.id) {
logger.error('MDot','Missing required parameter');
res.status(400).send({
status: 'error',
error: 'missing required parameter'
});
return;
}
if (req.query.hasOwnProperty('start') && req.query.hasOwnProperty('start')) {
data.start = req.query.start;
data.end = req.query.end;
}
if (req.params.hasOwnProperty('id')) {
data.id = req.params.id;
dbMdot.doGet(data)
.then((d) => {
res.json({events:d});
})
.catch((e) => {
logger.error(e);
res.status(500).json({});
});
}
});
app.use('/apiv2/mdot/', mdotRouter);
};