mirror of
https://github.com/Unleash/unleash.git
synced 2025-01-01 00:08:27 +01:00
50b56fd7a1
There is an example in eventRepositorySpec on how to listen on events.
57 lines
1.4 KiB
JavaScript
57 lines
1.4 KiB
JavaScript
var db = require('./db');
|
|
var EventRepository = require('./eventRepository');
|
|
var eventDb = new EventRepository();
|
|
|
|
module.exports = function (app) {
|
|
|
|
app.get('/features', function (req, res) {
|
|
// TODO svelovla, fix this
|
|
eventDb.create({name: 'testing method'});
|
|
db.getFeatures().then(function (features) {
|
|
res.json({features: features});
|
|
});
|
|
});
|
|
|
|
app.get('/features/:id', function (req, res) {
|
|
db.getFeature.then(function (feature) {
|
|
if (feature) {
|
|
res.json(feature);
|
|
} else {
|
|
res.json(404, {error: 'Could not find feature'});
|
|
}
|
|
});
|
|
});
|
|
|
|
app.post('/features', function (req, res) {
|
|
var newFeature = req.body;
|
|
|
|
db.getFeature(newFeature.name).then(function (feature) {
|
|
if (feature) {
|
|
res.status(500).end();
|
|
} else {
|
|
db.addFeature(newFeature).then(function () {
|
|
res.status(201).end();
|
|
});
|
|
}
|
|
});
|
|
});
|
|
|
|
app.patch('/features/:id', function (req, res) {
|
|
var body = req.body;
|
|
body.data.name = req.params.id;
|
|
var event = {};
|
|
event.user = req.connection.remoteAddress;
|
|
event.comment = body.comment;
|
|
event.data = body.data;
|
|
|
|
// console.log(event);
|
|
|
|
// db.save(event).then(function () {
|
|
res.status(204).end();
|
|
// });
|
|
|
|
});
|
|
|
|
};
|
|
|