2016-04-28 16:58:59 +02:00
|
|
|
var logger = require('../logger');
|
|
|
|
var eventType = require('../eventType');
|
|
|
|
var ValidationError = require('../error/ValidationError');
|
|
|
|
var validateRequest = require('../error/validateRequest');
|
2014-12-17 21:56:27 +01:00
|
|
|
|
2016-05-01 22:53:09 +02:00
|
|
|
module.exports = function (app, config) {
|
|
|
|
var featureDb = config.featureDb;
|
|
|
|
var eventStore = config.eventStore;
|
|
|
|
|
2014-12-17 21:56:27 +01:00
|
|
|
app.get('/archive/features', function (req, res) {
|
|
|
|
featureDb.getArchivedFeatures().then(function (archivedFeatures) {
|
2016-04-24 22:41:37 +02:00
|
|
|
res.json({ 'features': archivedFeatures });
|
2014-12-17 21:56:27 +01:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
app.post('/archive/revive', function (req, res) {
|
|
|
|
req.checkBody('name', 'Name is required').notEmpty();
|
|
|
|
|
|
|
|
validateRequest(req)
|
|
|
|
.then(function() {
|
|
|
|
return eventStore.create({
|
2015-02-09 18:28:51 +01:00
|
|
|
type: eventType.featureRevived,
|
2014-12-17 21:56:27 +01:00
|
|
|
createdBy: req.connection.remoteAddress,
|
|
|
|
data: req.body
|
|
|
|
});
|
|
|
|
}).then(function() {
|
|
|
|
res.status(200).end();
|
|
|
|
}).catch(ValidationError, function() {
|
|
|
|
res.status(400).json(req.validationErrors());
|
|
|
|
})
|
|
|
|
.catch(function(err) {
|
|
|
|
logger.error("Could not revive feature toggle", err);
|
|
|
|
res.status(500).end();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|