1
0
mirror of https://github.com/Unleash/unleash.git synced 2024-12-28 00:06:53 +01:00
unleash.unleash/lib/routes/feature-archive.js

45 lines
1.3 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
const handleErrors = (req, res, error) => {
switch (error.constructor) {
case ValidationError:
return res
.status(400)
.json(req.validationErrors())
.end();
default:
logger.error('Server failed executing request', error);
return res
.status(500)
.end();
}
};
module.exports = function (app, config) {
const { featureToggleStore, eventStore } = config.stores;
2016-06-18 21:53:18 +02:00
app.get('/archive/features', (req, res) => {
2016-11-05 10:16:48 +01:00
featureToggleStore.getArchivedFeatures().then(archivedFeatures => {
2016-06-18 21:53:18 +02:00
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-11-05 10:16:48 +01:00
.then(() => eventStore.store({
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(error => handleErrors(req, res, error));
2014-12-17 21:56:27 +01:00
});
};