mdot_server/lib/mdot/api.js

49 lines
1020 B
JavaScript
Raw Normal View History

2016-08-08 10:46:31 +00:00
var logger = require('log4js').getLogger();
var mdot = require('./mdot.js');
2016-08-08 10:46:31 +00:00
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');
2016-08-08 10:46:31 +00:00
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;
}
2016-08-08 10:46:31 +00:00
if (req.params.hasOwnProperty('id')) {
data.id = req.params.id;
mdot.doGet(data)
.then((d) => {
2016-08-08 10:46:31 +00:00
'use strict';
res.json(d);
})
.catch((e) => {
logger.error(e);
res.status(500).json({});
2016-08-08 10:46:31 +00:00
});
}
});
app.use('/api/mdot/', mdotRouter);
};