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

38 lines
1014 B
JavaScript

'use strict';
const Controller = require('../controller');
const { filter } = require('./util');
const version = 1;
class FeatureController extends Controller {
constructor({ featureToggleStore }) {
super();
this.toggleStore = featureToggleStore;
this.get('/', this.getAll);
this.get('/:featureName', this.getFeatureToggle);
}
async getAll(req, res) {
const nameFilter = filter('name', req.query.namePrefix);
const allFeatureToggles = await this.toggleStore.getFeatures();
const features = nameFilter(allFeatureToggles);
res.json({ version, features });
}
async getFeatureToggle(req, res) {
try {
const name = req.params.featureName;
const featureToggle = await this.toggleStore.getFeature(name);
res.json(featureToggle).end();
} catch (err) {
res.status(404).json({ error: 'Could not find feature' });
}
}
}
module.exports = FeatureController;