mdot_server/lib/mdot/track.js

52 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-08-12 13:07:22 +00:00
/**
*
* User: Martin Donnelly
* Date: 2016-08-12
* Time: 13:41
*
*/
'use strict';
var logger = require('log4js').getLogger();
var mdot = require('./mdot.js');
var db = require('../server/db-connector').dbConnection;
var dbTrack = require('../server/db-track')(db);
module.exports = function(app) {
var express = require('express');
var mdotRouter = express.Router();
mdotRouter.post('/', function(req, res) {
2016-08-12 13:11:03 +00:00
logger.debug('body',req.body);
2016-08-12 13:07:22 +00:00
var data = {};
if (!req.body.hasOwnProperty('locationid') || !req.body.hasOwnProperty('count') || !req.body.hasOwnProperty('total')) {
logger.error('MDot','Missing required parameter');
res.status(400).send({
status: 'error',
error: 'missing required parameter'
});
return;
} else {
data.locationid = req.body.locationid;
data.count = req.body.count;
data.total = req.body.total;
dbTrack.addNewTrack(data)
.then((d) => {
res.json({d: d});
})
.catch((e) => {
logger.error(e);
res.status(500).json({});
});
}
});
app.use('/apiv2/track/', mdotRouter);
};