2017-06-28 10:20:22 +02:00
|
|
|
'use strict';
|
|
|
|
|
2018-12-03 08:59:13 +01:00
|
|
|
const Controller = require('../controller');
|
2017-06-28 10:20:22 +02:00
|
|
|
|
|
|
|
const version = 1;
|
|
|
|
|
2021-01-22 13:39:42 +01:00
|
|
|
const FEATURE_COLUMNS_CLIENT = [
|
|
|
|
'name',
|
|
|
|
'type',
|
|
|
|
'enabled',
|
|
|
|
'stale',
|
|
|
|
'strategies',
|
|
|
|
'variants',
|
|
|
|
];
|
|
|
|
|
2018-12-03 08:59:13 +01:00
|
|
|
class FeatureController extends Controller {
|
2021-01-21 13:47:08 +01:00
|
|
|
constructor({ featureToggleService }, getLogger) {
|
2018-12-03 08:59:13 +01:00
|
|
|
super();
|
2021-01-18 12:32:19 +01:00
|
|
|
this.toggleService = featureToggleService;
|
2021-01-21 13:47:08 +01:00
|
|
|
this.logger = getLogger('client-api/feature.js');
|
2018-12-03 08:59:13 +01:00
|
|
|
this.get('/', this.getAll);
|
|
|
|
this.get('/:featureName', this.getFeatureToggle);
|
2018-11-24 15:02:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
async getAll(req, res) {
|
2021-01-22 13:39:42 +01:00
|
|
|
const features = await this.toggleService.getFeatures(
|
|
|
|
req.query,
|
|
|
|
FEATURE_COLUMNS_CLIENT,
|
|
|
|
);
|
2018-11-24 15:02:31 +01:00
|
|
|
res.json({ version, features });
|
|
|
|
}
|
|
|
|
|
|
|
|
async getFeatureToggle(req, res) {
|
|
|
|
try {
|
|
|
|
const name = req.params.featureName;
|
2021-01-18 12:32:19 +01:00
|
|
|
const featureToggle = await this.toggleService.getFeature(name);
|
2018-11-24 15:02:31 +01:00
|
|
|
res.json(featureToggle).end();
|
|
|
|
} catch (err) {
|
|
|
|
res.status(404).json({ error: 'Could not find feature' });
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports = FeatureController;
|