1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-22 19:07:54 +01:00
unleash.unleash/packages/unleash-api/lib/routes/feature-archive.js

34 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
2016-06-20 10:27:19 +02:00
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({
2016-06-18 21:55:46 +02:00
type: eventType.featureRevived,
createdBy: req.connection.remoteAddress,
data: req.body,
2016-07-02 11:54:50 +02:00
}))
.then(() => res.status(200).end())
.catch(ValidationError, () => res.status(400).json(req.validationErrors()))
2016-06-18 21:53:18 +02:00
.catch(err => {
2016-06-18 21:55:46 +02:00
logger.error('Could not revive feature toggle', err);
2014-12-17 21:56:27 +01:00
res.status(500).end();
});
});
};