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:
parent
ed2f1a5d8d
commit
d2a09d89b9
10
unleash-server/lib/eventApi.js
Normal file
10
unleash-server/lib/eventApi.js
Normal 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});
|
||||
});
|
||||
});
|
||||
};
|
@ -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
|
||||
};
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user