1
0
mirror of https://github.com/Unleash/unleash.git synced 2025-01-20 00:08:02 +01:00

Adding events api

This commit is contained in:
Gard Rimestad 2014-10-24 15:32:33 +02:00 committed by Ivar Conradi Østhus
parent ed2f1a5d8d
commit d2a09d89b9
3 changed files with 33 additions and 1 deletions

View File

@ -0,0 +1,10 @@
var eventDb = require('./eventDb');
module.exports = function (app) {
app.get('/events', function (req, res) {
eventDb.getEvents().then(function (events) {
res.json({events: events});
});
});
};

View File

@ -13,6 +13,26 @@ function storeEvent(event) {
});
}
function getEvents() {
var sql = 'SELECT id, type, created_by as created, data FROM events ORDER BY created_at DESC';
return new Promise(function (resolve, reject) {
dbPool.query(sql, function(err, res) {
if(err) {reject(err);}
resolve(res.rows.map(mapToEvent));
});
});
}
function mapToEvent(row) {
return {
id: row.id,
type: row.type,
createdBy: row.created,
data: row.data
};
}
module.exports = {
store: storeEvent
store: storeEvent,
getEvents: getEvents
};

View File

@ -3,6 +3,7 @@ var express = require('express'),
log4js = require('log4js'),
logger = require('./lib/logger'),
routes = require('./lib/routes'),
eventApi = require('./lib/eventApi'),
featureApi = require('./lib/featureApi'),
validator = require('express-validator'),
app = express(),
@ -24,6 +25,7 @@ app.set('port', process.env.HTTP_PORT || 4242);
app.use(baseUriPath, express.static(__dirname + '/public'));
app.use(bodyParser.json({strict: false}));
eventApi(router);
featureApi(router);
routes(router);
app.use(baseUriPath, router);