1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00

Adding events/:name

This commit is contained in:
Gard Rimestad 2014-11-14 07:13:08 +01:00
parent 04bd33c5f9
commit 360c1bc37a
2 changed files with 24 additions and 0 deletions

View File

@ -7,4 +7,16 @@ module.exports = function (app) {
res.json({events: events});
});
});
app.get('/events/:name', function (req, res) {
eventDb.getEvents(req.params.name).then(function (events) {
if (events) {
res.json(events);
} else {
res.status(404).json({error: 'Could not find events'});
}
});
});
};

View File

@ -23,6 +23,18 @@ function getEvents() {
});
}
function getEvents(name) {
var sql = 'SELECT id, type, created_by as created, data ' +
'FROM events WHERE data ->> \'name\' = $1 ' +
'ORDER BY created_at DESC';
return new Promise(function (resolve, reject) {
dbPool.query(sql, [name], function(err, res) {
if(err) {reject(err);}
resolve(res.rows.map(mapToEvent));
});
});
}
function mapToEvent(row) {
return {
id: row.id,