UNPKG

unleash-server

Version:

Unleash is an enterprise ready feature flag service. It provides different strategies for handling feature flags.

38 lines 1.85 kB
import { NONE, } from '../../types/index.js'; import { createResponseSchema, getStandardResponses, } from '../../openapi/index.js'; import Controller from '../../routes/controller.js'; import { featureLifecycleCountSchema, } from '../../openapi/spec/feature-lifecycle-count-schema.js'; export default class FeatureLifecycleCountController extends Controller { constructor(config, { openApiService }, { featureLifecycleReadModel, }) { super(config); this.featureLifecycleReadModel = featureLifecycleReadModel; this.openApiService = openApiService; this.route({ method: 'get', path: '/count', handler: this.getStageCount, permission: NONE, middleware: [ openApiService.validPath({ tags: ['Unstable'], summary: 'Get all features lifecycle stage count', description: 'Information about the number of features in each lifecycle stage.', operationId: 'getFeatureLifecycleStageCount', responses: { 200: createResponseSchema('featureLifecycleCountSchema'), ...getStandardResponses(401, 403, 404), }, }), ], }); } async getStageCount(_, res) { const stageCounts = await this.featureLifecycleReadModel.getStageCount(); const result = stageCounts.reduce((acc, { stage, count }) => { acc[stage === 'pre-live' ? 'preLive' : stage] = count; return acc; }, { initial: 0, preLive: 0, live: 0, completed: 0, archived: 0 }); this.openApiService.respondWithValidation(200, res, featureLifecycleCountSchema.$id, result); } } //# sourceMappingURL=feature-lifecycle-count-controller.js.map