mirror of
https://gitlab.silvrtree.co.uk/martind2000/mdot_server.git
synced 2025-01-31 09:50:14 +00:00
86 lines
1.8 KiB
JavaScript
86 lines
1.8 KiB
JavaScript
/**
|
|
*
|
|
* User: Martin Donnelly
|
|
* Date: 2016-08-12
|
|
* Time: 13:41
|
|
*
|
|
*/
|
|
'use strict';
|
|
var logger = require('log4js').getLogger();
|
|
|
|
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 (!Object.hasOwnProperty.call(body, 'locationid') || !Object.hasOwnProperty.call(body, 'count') || !Object.hasOwnProperty.call(body, '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({});
|
|
});
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
mdotRouter.get('/:id', function(req, res) {
|
|
console.log(req.headers);
|
|
|
|
var data = {};
|
|
logger.debug('track-GetData');
|
|
|
|
if (!req.params.id) {
|
|
logger.error('Track','Missing required parameter');
|
|
res.status(400).send({
|
|
status: 'error',
|
|
error: 'missing required parameter'
|
|
});
|
|
return;
|
|
}
|
|
|
|
if (req.params.hasOwnProperty('id')) {
|
|
data.locationid = req.params.id;
|
|
|
|
dbTrack.doGet(data)
|
|
.then((d) => {
|
|
res.json({tracks:d});
|
|
})
|
|
.catch((e) => {
|
|
logger.error(e);
|
|
res.status(500).json({});
|
|
});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
app.use('/apiv2/track/', mdotRouter);
|
|
};
|
|
|