diff --git a/backend/packages/Upgrade/src/api/controllers/FeatureFlagController.ts b/backend/packages/Upgrade/src/api/controllers/FeatureFlagController.ts index 76c14f4f14..0fe579627c 100644 --- a/backend/packages/Upgrade/src/api/controllers/FeatureFlagController.ts +++ b/backend/packages/Upgrade/src/api/controllers/FeatureFlagController.ts @@ -10,8 +10,13 @@ import { } from './validators/FeatureFlagsPaginatedParamsValidator'; import { FeatureFlagFilterModeUpdateValidator } from './validators/FeatureFlagFilterModeUpdateValidator'; import { AppRequest, PaginationResponse } from '../../types'; -import { SERVER_ERROR, IFeatureFlagFile } from 'upgrade_types'; -import { FeatureFlagValidation, IdValidator, UserParamsValidator } from './validators/FeatureFlagValidator'; +import { SERVER_ERROR } from 'upgrade_types'; +import { + FeatureFlagImportValidation, + FeatureFlagValidation, + IdValidator, + UserParamsValidator, +} from './validators/FeatureFlagValidator'; import { ExperimentUserService } from '../services/ExperimentUserService'; import { FeatureFlagListValidator } from '../controllers/validators/FeatureFlagListValidator'; import { Segment } from 'src/api/models/Segment'; @@ -314,7 +319,7 @@ export class FeatureFlagsController { * parameters: * - in: body * name: statusUpdate - * description: Updating the featur flag's status + * description: Updating the feature flag's status * schema: * type: object * required: @@ -352,7 +357,7 @@ export class FeatureFlagsController { * parameters: * - in: body * name: updateFilterMode - * description: Updating the featur flag's filter mode + * description: Updating the feature flag's filter mode * schema: * type: object * required: @@ -457,7 +462,7 @@ export class FeatureFlagsController { * - application/json * parameters: * - in: body - * name: addinclusionList + * name: add inclusionList * description: Adding an inclusion list to the feature flag * schema: * type: object @@ -701,9 +706,9 @@ export class FeatureFlagsController { */ @Post('/import/validation') public async validateImportFeatureFlags( - @Body({ validate: true }) featureFlags: IFeatureFlagFile[], + @Body({ validate: true }) featureFlags: FeatureFlagImportValidation, @Req() request: AppRequest ): Promise { - return await this.featureFlagService.validateImportFeatureFlags(featureFlags, request.logger); + return await this.featureFlagService.validateImportFeatureFlags(featureFlags.files, request.logger); } } diff --git a/backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagValidator.ts b/backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagValidator.ts index 7a700c8fa4..55650c2145 100644 --- a/backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagValidator.ts +++ b/backend/packages/Upgrade/src/api/controllers/validators/FeatureFlagValidator.ts @@ -73,3 +73,22 @@ export class IdValidator { @IsUUID() public id: string; } + +export class FeatureFlagImportValidation { + @IsArray() + @ValidateNested({ each: true }) + @Type(() => FeatureFlagFile) + public files: FeatureFlagFile[]; +} + +class FeatureFlagFile { + @IsString() + @IsNotEmpty() + @IsDefined() + public fileName: string; + + @IsString() + @IsNotEmpty() + @IsDefined() + public fileContent: string; +} diff --git a/frontend/projects/upgrade/src/app/core/feature-flags/feature-flags.data.service.ts b/frontend/projects/upgrade/src/app/core/feature-flags/feature-flags.data.service.ts index a3ccf47e50..9e47713dfb 100644 --- a/frontend/projects/upgrade/src/app/core/feature-flags/feature-flags.data.service.ts +++ b/frontend/projects/upgrade/src/app/core/feature-flags/feature-flags.data.service.ts @@ -45,12 +45,12 @@ export class FeatureFlagsDataService { return this.http.put(url, flag); } - validateFeatureFlag(featureFlag: IFeatureFlagFile[]) { + validateFeatureFlag(featureFlag: { files: IFeatureFlagFile[] }) { const url = this.environment.api.validateFeatureFlag; return this.http.post(url, featureFlag); } - importFeatureFlag(featureFlag: IFeatureFlagFile[]) { + importFeatureFlag(featureFlag: { files: IFeatureFlagFile[] }) { const url = this.environment.api.importFeatureFlag; return this.http.post(url, featureFlag); } diff --git a/frontend/projects/upgrade/src/app/features/dashboard/feature-flags/modals/import-feature-flag-modal/import-feature-flag-modal.component.ts b/frontend/projects/upgrade/src/app/features/dashboard/feature-flags/modals/import-feature-flag-modal/import-feature-flag-modal.component.ts index 1604c18bc7..4176014fb8 100644 --- a/frontend/projects/upgrade/src/app/features/dashboard/feature-flags/modals/import-feature-flag-modal/import-feature-flag-modal.component.ts +++ b/frontend/projects/upgrade/src/app/features/dashboard/feature-flags/modals/import-feature-flag-modal/import-feature-flag-modal.component.ts @@ -4,7 +4,7 @@ import { CommonStatusIndicatorChipComponent, } from '../../../../../shared-standalone-component-lib/components'; import { BehaviorSubject, Observable, combineLatest, firstValueFrom, map } from 'rxjs'; -import { MAT_DIALOG_DATA, MatDialog, MatDialogRef } from '@angular/material/dialog'; +import { MAT_DIALOG_DATA, MatDialogRef } from '@angular/material/dialog'; import { CommonModule } from '@angular/common'; import { SharedModule } from '../../../../../shared/shared.module'; import { CommonImportContainerComponent } from '../../../../../shared-standalone-component-lib/components/common-import-container/common-import-container.component'; @@ -87,7 +87,7 @@ export class ImportFeatureFlagModalComponent { async checkValidation(files: IFeatureFlagFile[]) { try { const validationErrors = (await firstValueFrom( - this.featureFlagsDataService.validateFeatureFlag(files) + this.featureFlagsDataService.validateFeatureFlag({ files: files }) )) as ValidateFeatureFlagError[]; this.fileValidationErrors = validationErrors.filter((data) => data.compatibilityType != null) || []; this.fileValidationErrorDataSource.data = this.fileValidationErrors; @@ -114,7 +114,7 @@ export class ImportFeatureFlagModalComponent { try { this.isImportActionBtnDisabled.next(true); const importResult = (await firstValueFrom( - this.featureFlagsDataService.importFeatureFlag(this.fileData) + this.featureFlagsDataService.importFeatureFlag({ files: this.fileData }) )) as importError[]; this.showNotification(importResult);