mirror of
https://gitlab.silvrtree.co.uk/martind2000/mdot_server.git
synced 2025-01-31 09:00:13 +00:00
54 lines
1.2 KiB
JavaScript
54 lines
1.2 KiB
JavaScript
/**
|
|
*
|
|
* 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) {
|
|
|
|
|
|
var body = req.body;
|
|
var data = {};
|
|
logger.debug('body', body);
|
|
if (!body.hasOwnProperty('locationid') || !body.hasOwnProperty('count') || !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);
|
|
};
|
|
|