Skip to content

Commit

Permalink
Merge pull request #1825 from CarnegieLearningWeb/featureflag/import-api
Browse files Browse the repository at this point in the history
FeatureFlag import API
  • Loading branch information
Yagnik56 authored Aug 26, 2024
2 parents 41f4031 + 07f7755 commit 675650f
Show file tree
Hide file tree
Showing 10 changed files with 248 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
} from './validators/FeatureFlagsPaginatedParamsValidator';
import { FeatureFlagFilterModeUpdateValidator } from './validators/FeatureFlagFilterModeUpdateValidator';
import { AppRequest, PaginationResponse } from '../../types';
import { SERVER_ERROR } from 'upgrade_types';
import { IImportError, SERVER_ERROR } from 'upgrade_types';
import {
FeatureFlagImportValidation,
FeatureFlagValidation,
Expand Down Expand Up @@ -480,7 +480,7 @@ export class FeatureFlagsController {
@Body({ validate: true }) inclusionList: FeatureFlagListValidator,
@Req() request: AppRequest
): Promise<FeatureFlagSegmentInclusion> {
return this.featureFlagService.addList(inclusionList, 'inclusion', request.logger);
return (await this.featureFlagService.addList([inclusionList], 'inclusion', request.logger))[0];
}

/**
Expand Down Expand Up @@ -510,7 +510,7 @@ export class FeatureFlagsController {
@Body({ validate: true }) exclusionList: FeatureFlagListValidator,
@Req() request: AppRequest
): Promise<FeatureFlagSegmentExclusion> {
return this.featureFlagService.addList(exclusionList, 'exclusion', request.logger);
return (await this.featureFlagService.addList([exclusionList], 'exclusion', request.logger))[0];
}

/**
Expand Down Expand Up @@ -711,4 +711,55 @@ export class FeatureFlagsController {
): Promise<ValidatedFeatureFlagsError[]> {
return await this.featureFlagService.validateImportFeatureFlags(featureFlags.files, request.logger);
}

/**
* @swagger
* /flags/import:
* post:
* description: Validating Feature Flag
* consumes:
* - application/json
* parameters:
* - in: body
* name: featureFlags
* required: true
* schema:
* type: array
* items:
* type: object
* properties:
* fileName:
* type: string
* fileContent:
* type: string
* description: Import FeatureFlag Files
* tags:
* - Feature Flags
* produces:
* - application/json
* responses:
* '200':
* description: Validations are completed
* schema:
* type: array
* items:
* type: object
* properties:
* fileName:
* type: string
* compatibilityType:
* type: string
* enum: [compatible, warning, incompatible]
* '401':
* description: AuthorizationRequiredError
* '500':
* description: Internal Server Error
*/
@Post('/import')
public async importFeatureFlags(
@Body({ validate: true }) featureFlags: FeatureFlagImportValidation,
@Req() request: AppRequest
): Promise<IImportError[]> {
return await this.featureFlagService.importFeatureFlags(featureFlags.files, request.logger);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FeatureFlagSegmentExclusion } from '../models/FeatureFlagSegmentExclusi
@EntityRepository(FeatureFlagSegmentExclusion)
export class FeatureFlagSegmentExclusionRepository extends Repository<FeatureFlagSegmentExclusion> {
public async insertData(
data: Partial<FeatureFlagSegmentExclusion>,
data: Partial<FeatureFlagSegmentExclusion>[],
logger: UpgradeLogger,
entityManager: EntityManager
): Promise<FeatureFlagSegmentExclusion> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { FeatureFlagSegmentInclusion } from '../models/FeatureFlagSegmentInclusi
@EntityRepository(FeatureFlagSegmentInclusion)
export class FeatureFlagSegmentInclusionRepository extends Repository<FeatureFlagSegmentInclusion> {
public async insertData(
data: Partial<FeatureFlagSegmentInclusion>,
data: Partial<FeatureFlagSegmentInclusion>[],
logger: UpgradeLogger,
entityManager: EntityManager
): Promise<FeatureFlagSegmentInclusion> {
Expand Down
Loading

0 comments on commit 675650f

Please sign in to comment.