Skip to content

Commit

Permalink
update import API validations
Browse files Browse the repository at this point in the history
  • Loading branch information
RidhamShah committed Aug 20, 2024
1 parent 9361c54 commit 3828069
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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<ValidatedFeatureFlagsError[]> {
return await this.featureFlagService.validateImportFeatureFlags(featureFlags, request.logger);
return await this.featureFlagService.validateImportFeatureFlags(featureFlags.files, request.logger);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,12 @@ export class FeatureFlagsDataService {
return this.http.put<FeatureFlag>(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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand All @@ -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);
Expand Down

0 comments on commit 3828069

Please sign in to comment.