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

35 lines
1.1 KiB
JavaScript
Raw Normal View History

2016-06-18 21:53:18 +02:00
'use strict';
2016-10-26 10:43:11 +02:00
2016-06-20 10:27:19 +02:00
const logger = require('../logger');
2016-10-27 20:51:21 +02:00
const eventType = require('../event-type');
const ValidationError = require('../error/validation-error');
const validateRequest = require('../error/validate-request');
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();
});
});
};