mdot_server/lib/mdot/meeting.js
2016-08-18 15:49:57 +01:00

90 lines
2.0 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 dbMeeting = require('../server/db-meeting')(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, 'roomId') ||
!Object.hasOwnProperty.call(body, 'start') ||
!Object.hasOwnProperty.call(body, 'end') ||
!Object.hasOwnProperty.call(body, 'occupancy')){
logger.error('Meeting','Missing required parameter');
res.status(400).send({
status: 'error',
error: 'missing required parameter'
});
return;
} else {
data.locationid = req.body.roomId;
data.count = req.body.occupancy;
data.start = req.body.start;
data.end = req.body.end;
dbMeeting.addNewMeeting(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;
dbMeeting.doGet(data)
.then((d) => {
res.json({tracks:d});
})
.catch((e) => {
logger.error(e);
res.status(500).json({});
});
}
});
app.use('/apiv2/meeting/', mdotRouter);
};