From 4ea00e4b7e8e2cda441e019b6e062ec9d446c75f Mon Sep 17 00:00:00 2001 From: ivaosthu Date: Thu, 29 Nov 2018 21:01:53 +0100 Subject: [PATCH] chore: Simplify client-controller constructor --- lib/routes/client-api/feature.js | 8 ++++---- lib/routes/client-api/index.js | 8 +++++--- lib/routes/client-api/metrics.js | 2 +- lib/routes/client-api/register.js | 2 +- lib/routes/index.js | 5 ++++- 5 files changed, 15 insertions(+), 10 deletions(-) diff --git a/lib/routes/client-api/feature.js b/lib/routes/client-api/feature.js index f38632b36e..5a3b0106ab 100644 --- a/lib/routes/client-api/feature.js +++ b/lib/routes/client-api/feature.js @@ -6,10 +6,10 @@ const { filter } = require('./util'); const version = 1; class FeatureController { - constructor(config) { + constructor({ featureToggleStore }) { const router = Router(); this._router = router; - this.store = config.stores.featureToggleStore; + this.toggleStore = featureToggleStore; router.get('/', (req, res) => this.getAll(req, res)); router.get('/:featureName', this.getFeatureToggle.bind(this)); @@ -18,7 +18,7 @@ class FeatureController { async getAll(req, res) { const nameFilter = filter('name', req.query.namePrefix); - const allFeatureToggles = await this.store.getFeatures(); + const allFeatureToggles = await this.toggleStore.getFeatures(); const features = nameFilter(allFeatureToggles); res.json({ version, features }); @@ -27,7 +27,7 @@ class FeatureController { async getFeatureToggle(req, res) { try { const name = req.params.featureName; - const featureToggle = await this.store.getFeature(name); + const featureToggle = await this.toggleStore.getFeature(name); res.json(featureToggle).end(); } catch (err) { res.status(404).json({ error: 'Could not find feature' }); diff --git a/lib/routes/client-api/index.js b/lib/routes/client-api/index.js index 2931edea51..112aa1efe2 100644 --- a/lib/routes/client-api/index.js +++ b/lib/routes/client-api/index.js @@ -11,10 +11,12 @@ class ClientApi { const router = Router(); this._router = router; + const stores = config.stores; + router.get('/', this.index); - router.use('/features', new FeatureController(config).router()); - router.use('/metrics', new MetricsController(config).router()); - router.use('/register', new RegisterController(config).router()); + router.use('/features', new FeatureController(stores).router()); + router.use('/metrics', new MetricsController(stores).router()); + router.use('/register', new RegisterController(stores).router()); } index(req, res) { diff --git a/lib/routes/client-api/metrics.js b/lib/routes/client-api/metrics.js index 1cb89686f7..74d109b644 100644 --- a/lib/routes/client-api/metrics.js +++ b/lib/routes/client-api/metrics.js @@ -7,7 +7,7 @@ const logger = require('../../logger')('client-api/metrics.js'); const { clientMetricsSchema } = require('./metrics-schema'); class ClientMetricsController { - constructor({ stores: { clientMetricsStore, clientInstanceStore } }) { + constructor({ clientMetricsStore, clientInstanceStore }) { const router = Router(); this.clientMetricsStore = clientMetricsStore; this.clientInstanceStore = clientInstanceStore; diff --git a/lib/routes/client-api/register.js b/lib/routes/client-api/register.js index 62937fbc10..6223dbbbee 100644 --- a/lib/routes/client-api/register.js +++ b/lib/routes/client-api/register.js @@ -7,7 +7,7 @@ const logger = require('../../logger')('/client-api/register.js'); const { clientRegisterSchema: schema } = require('./register-schema'); class RegisterController { - constructor({ stores: { clientInstanceStore, clientApplicationsStore } }) { + constructor({ clientInstanceStore, clientApplicationsStore }) { const router = Router(); this._router = router; this.clientInstanceStore = clientInstanceStore; diff --git a/lib/routes/index.js b/lib/routes/index.js index 5ca5981988..f4a9079493 100644 --- a/lib/routes/index.js +++ b/lib/routes/index.js @@ -29,7 +29,10 @@ class IndexRouter { // legacy support (remove in 4.x) if (config.enableLegacyRoutes) { - router.use('/api/features', new FeatureController(config).router()); + router.use( + '/api/features', + new FeatureController(config.stores).router() + ); } }