1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-10-18 20:09:08 +02:00
unleash.unleash/packages/unleash-api/lib/routes/feature-archive.js

36 lines
1.2 KiB
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
const logger = require('../logger');
const eventType = require('../eventType');
const ValidationError = require('../error/ValidationError');
const validateRequest = require('../error/validateRequest');
2014-12-17 21:56:27 +01:00
module.exports = function (app, config) {
2016-06-18 21:53:18 +02:00
const featureDb = config.featureDb;
const eventStore = config.eventStore;
2016-06-18 21:53:18 +02:00
app.get('/archive/features', (req, res) => {
featureDb.getArchivedFeatures().then(archivedFeatures => {
res.json({ features: archivedFeatures });
2014-12-17 21:56:27 +01:00
});
});
2016-06-18 21:53:18 +02:00
app.post('/archive/revive', (req, res) => {
2014-12-17 21:56:27 +01:00
req.checkBody('name', 'Name is required').notEmpty();
validateRequest(req)
2016-06-18 21:53:18 +02:00
.then(() => eventStore.create({
type: eventType.featureRevived,
createdBy: req.connection.remoteAddress,
data: req.body
})).then(() => {
2014-12-17 21:56:27 +01:00
res.status(200).end();
2016-06-18 21:53:18 +02:00
}).catch(ValidationError, () => {
2014-12-17 21:56:27 +01:00
res.status(400).json(req.validationErrors());
})
2016-06-18 21:53:18 +02:00
.catch(err => {
2014-12-17 21:56:27 +01:00
logger.error("Could not revive feature toggle", err);
res.status(500).end();
});
});
};