2014-10-21 13:10:15 +02:00
|
|
|
var db = require('./db');
|
2014-10-22 15:35:22 +02:00
|
|
|
var EventRepository = require('./eventRepository');
|
|
|
|
var eventDb = new EventRepository();
|
2014-10-20 15:12:30 +02:00
|
|
|
|
2014-10-20 13:03:43 +02:00
|
|
|
module.exports = function (app) {
|
2014-10-20 15:12:30 +02:00
|
|
|
|
2014-10-20 13:03:43 +02:00
|
|
|
app.get('/features', function (req, res) {
|
2014-10-22 15:35:22 +02:00
|
|
|
// TODO svelovla, fix this
|
|
|
|
eventDb.create({name: 'testing method'});
|
2014-10-21 13:10:15 +02:00
|
|
|
db.getFeatures().then(function (features) {
|
2014-10-21 15:56:17 +02:00
|
|
|
res.json({features: features});
|
2014-10-21 13:10:15 +02:00
|
|
|
});
|
2014-10-20 15:12:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/features/:id', function (req, res) {
|
2014-10-21 13:10:15 +02:00
|
|
|
db.getFeature.then(function (feature) {
|
|
|
|
if (feature) {
|
|
|
|
res.json(feature);
|
|
|
|
} else {
|
|
|
|
res.json(404, {error: 'Could not find feature'});
|
|
|
|
}
|
|
|
|
});
|
2014-10-20 15:12:30 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
app.post('/features', function (req, res) {
|
|
|
|
var newFeature = req.body;
|
|
|
|
|
2014-10-21 13:10:15 +02:00
|
|
|
db.getFeature(newFeature.name).then(function (feature) {
|
|
|
|
if (feature) {
|
|
|
|
res.status(500).end();
|
|
|
|
} else {
|
|
|
|
db.addFeature(newFeature).then(function () {
|
|
|
|
res.status(201).end();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2014-10-20 13:03:43 +02:00
|
|
|
});
|
2014-10-20 15:12:30 +02:00
|
|
|
|
2014-10-21 15:28:10 +02:00
|
|
|
app.patch('/features/:id', function (req, res) {
|
2014-10-21 16:02:23 +02:00
|
|
|
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();
|
|
|
|
// });
|
|
|
|
|
2014-10-21 15:28:10 +02:00
|
|
|
});
|
|
|
|
|
2014-10-20 15:12:30 +02:00
|
|
|
};
|
|
|
|
|