2014-10-20 15:12:30 +02:00
|
|
|
var featuresMock = require('./featuresMock');
|
|
|
|
|
|
|
|
function getFeature(name) {
|
|
|
|
var featureFound;
|
|
|
|
featuresMock.forEach(function (feature) {
|
|
|
|
if (feature.name === name) {
|
|
|
|
featureFound = feature;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return featureFound;
|
|
|
|
}
|
|
|
|
|
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-20 15:12:30 +02:00
|
|
|
res.json(featuresMock);
|
|
|
|
});
|
|
|
|
|
|
|
|
app.get('/features/:id', function (req, res) {
|
|
|
|
var feature = getFeature(req.params.id);
|
|
|
|
|
|
|
|
if (feature) {
|
|
|
|
res.json(feature);
|
|
|
|
} else {
|
|
|
|
res.json(404, {error: 'Could not find feature'});
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
app.post('/features', function (req, res) {
|
|
|
|
var newFeature = req.body;
|
|
|
|
|
|
|
|
if (!getFeature(newFeature.name)) {
|
|
|
|
featuresMock.push(newFeature);
|
|
|
|
res.status(201).end();
|
|
|
|
} else {
|
|
|
|
res.status(500).end();
|
|
|
|
}
|
2014-10-20 13:03:43 +02:00
|
|
|
});
|
2014-10-20 15:12:30 +02:00
|
|
|
|
|
|
|
};
|
|
|
|
|