mirror of
https://github.com/Unleash/unleash.git
synced 2024-12-28 00:06:53 +01:00
Adding events/:name
This commit is contained in:
parent
04bd33c5f9
commit
360c1bc37a
@ -7,4 +7,16 @@ module.exports = function (app) {
|
|||||||
res.json({events: events});
|
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'});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
@ -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) {
|
function mapToEvent(row) {
|
||||||
return {
|
return {
|
||||||
id: row.id,
|
id: row.id,
|
||||||
|
Loading…
Reference in New Issue
Block a user