Skip to content

Commit

Permalink
Merge branch 'dev' into bugfix/bar-chart-initial-display-correct-cond…
Browse files Browse the repository at this point in the history
…ition-color
  • Loading branch information
ppratikcr7 authored Jun 3, 2024
2 parents 19d55ff + 2c285e5 commit cb3e4a4
Show file tree
Hide file tree
Showing 157 changed files with 2,773 additions and 998 deletions.
216 changes: 178 additions & 38 deletions backend/packages/Upgrade/src/api/controllers/FeatureFlagController.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import { JsonController, Authorized, Post, Body, CurrentUser, Delete, Param, Put, Req } from 'routing-controllers';
import { JsonController, Authorized, Post, Body, CurrentUser, Delete, Param, Put, Req, Get } from 'routing-controllers';
import { FeatureFlagService } from '../services/FeatureFlagService';
import { FeatureFlag } from '../models/FeatureFlag';
import { User } from '../models/User';
import { FeatureFlagStatusUpdateValidator } from './validators/FeatureFlagStatusUpdateValidator';
import { FeatureFlagPaginatedParamsValidator } from './validators/FeatureFlagsPaginatedParamsValidator';
import { AppRequest, PaginationResponse } from '../../types';
import { SERVER_ERROR } from 'upgrade_types';
import { isUUID } from 'class-validator';
import { FeatureFlagValidation } from './validators/FeatureFlagValidator';

interface FeatureFlagsPaginationInfo extends PaginationResponse {
Expand All @@ -21,9 +22,8 @@ interface FeatureFlagsPaginationInfo extends PaginationResponse {
* - name
* - key
* - description
* - variationType
* - status
* - variations
* - context
* properties:
* id:
* type: string
Expand All @@ -33,29 +33,101 @@ interface FeatureFlagsPaginationInfo extends PaginationResponse {
* type: string
* description:
* type: string
* variationType:
* type: string
* status:
* type: boolean
* variations:
* type: array
* items:
* type: object
* properties:
* value:
* type: string
* name:
* type: string
* description:
* type: string
* defaultVariation:
* type: boolean[]
* type: string
* enum: [archived, enabled, disabled]
* context:
* type: array
* items:
* type: string
* tags:
* type: array
* items:
* type: string
* featureFlagSegmentInclusion:
* type: object
* properties:
* segment:
* type: object
* properties:
* type:
* type: string
* example: private
* individualForSegment:
* type: array
* items:
* type: object
* properties:
* userId:
* type: string
* example: user1
* groupForSegment:
* type: array
* items:
* type: object
* properties:
* groupId:
* type: string
* example: school1
* type:
* type: string
* example: schoolId
* subSegments:
* type: array
* items:
* type: object
* properties:
* id:
* type: string
* name:
* type: string
* context:
* type: string
* featureFlagSegmentExclusion:
* type: object
* properties:
* segment:
* type: object
* properties:
* type:
* type: string
* example: private
* individualForSegment:
* type: array
* items:
* type: object
* properties:
* userId:
* type: string
* example: user1
* groupForSegment:
* type: array
* items:
* type: object
* properties:
* groupId:
* type: string
* example: school1
* type:
* type: string
* example: schoolId
* subSegments:
* type: array
* items:
* type: object
* properties:
* id:
* type: string
* name:
* type: string
* context:
* type: string
*/

/**
* @swagger
* flags:
* - name: Feature flags
* - name: Feature Flags
* description: Get Feature flags related data
*/

Expand All @@ -64,6 +136,71 @@ interface FeatureFlagsPaginationInfo extends PaginationResponse {
export class FeatureFlagsController {
constructor(public featureFlagService: FeatureFlagService) {}

/**
* @swagger
* /flags:
* get:
* description: Get all the feature flags
* tags:
* - Feature Flags
* produces:
* - application/json
* responses:
* '200':
* description: Feature Flag List
* schema:
* type: array
* items:
* $ref: '#/definitions/FeatureFlag'
* '401':
* description: AuthorizationRequiredError
*/

@Get()
public find(@Req() request: AppRequest): Promise<FeatureFlag[]> {
return this.featureFlagService.find(request.logger);
}

/**
* @swagger
* /flags/{id}:
* get:
* description: Get feature flag by id
* parameters:
* - in: path
* name: id
* required: true
* schema:
* type: string
* description: Feature Flag Id
* tags:
* - Feature Flags
* produces:
* - application/json
* responses:
* '200':
* description: Get Feature Flag By Id
* schema:
* $ref: '#/definitions/FeatureFlag'
* '401':
* description: AuthorizationRequiredError
* '404':
* description: Feature Flag not found
* '500':
* description: id should be of type UUID
*/
@Get('/:id')
public findOne(@Param('id') id: string, @Req() request: AppRequest): Promise<FeatureFlag | undefined> {
if (!isUUID(id)) {
return Promise.reject(
new Error(
JSON.stringify({ type: SERVER_ERROR.INCORRECT_PARAM_FORMAT, message: ' : id should be of type UUID.' })
)
);
}
return this.featureFlagService.findOne(id, request.logger);
}

/**
* @swagger
* /flags/paginated:
Expand All @@ -90,26 +227,27 @@ export class FeatureFlagsController {
* properties:
* key:
* type: string
* enum: [all, name, key, status, variation Type]
* enum: [all, name, key, status, tag, context]
* string:
* type: string
* sortParams:
* type: object
* properties:
* key:
* type: string
* enum: [name, key, status, variationType]
* enum: [name, key, status, updatedAt]
* sortAs:
* type: string
* enum: [ASC, DESC]
* tags:
* - Feature flags
* - Feature Flags
* produces:
* - application/json
* responses:
* '200':
* description: Get Paginated Experiments
* description: Get Paginated Feature Flags
*/

@Post('/paginated')
public async paginatedFind(
@Body({ validate: true })
Expand Down Expand Up @@ -157,7 +295,7 @@ export class FeatureFlagsController {
* $ref: '#/definitions/FeatureFlag'
* description: Feature flag structure
* tags:
* - Feature flags
* - Feature Flags
* produces:
* - application/json
* responses:
Expand All @@ -182,19 +320,21 @@ export class FeatureFlagsController {
* - application/json
* parameters:
* - in: body
* name: flagId
* required: true
* name: statusUpdate
* description: Updating the featur flag's status
* schema:
* type: string
* description: Flag ID
* - in: body
* name: status
* required: true
* schema:
* type: boolean
* description: Flag State
* type: object
* required:
* - flagId
* - status
* properties:
* flagId:
* type: string
* status:
* type: string
* enum: [archived, enabled, disabled]
* tags:
* - Feature flags
* - Feature Flags
* produces:
* - application/json
* responses:
Expand Down Expand Up @@ -222,7 +362,7 @@ export class FeatureFlagsController {
* type: string
* description: Feature flag Id
* tags:
* - Feature flags
* - Feature Flags
* produces:
* - application/json
* responses:
Expand Down Expand Up @@ -265,7 +405,7 @@ export class FeatureFlagsController {
* $ref: '#/definitions/FeatureFlag'
* description: Feature Flag Structure
* tags:
* - Feature flags
* - Feature Flags
* produces:
* - application/json
* responses:
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { IsNotEmpty, IsDefined, IsString, IsArray, IsEnum } from 'class-validator';
import { IsNotEmpty, IsDefined, IsString, IsArray, IsEnum, IsOptional, ValidateNested } from 'class-validator';
import { ParticipantsValidator } from '../../DTO/ExperimentDTO';
import { FILTER_MODE } from 'upgrade_types';
import { FEATURE_FLAG_STATUS } from 'upgrade_types';
import { Type } from 'class-transformer';

export class FeatureFlagValidation {
@IsNotEmpty()
@IsDefined()
@IsOptional()
@IsString()
id: string;

Expand All @@ -13,8 +14,7 @@ export class FeatureFlagValidation {
@IsString()
name: string;

@IsNotEmpty()
@IsDefined()
@IsOptional()
@IsString()
description: string;

Expand All @@ -40,4 +40,14 @@ export class FeatureFlagValidation {
@IsNotEmpty()
@IsArray()
public tags: string[];

@IsNotEmpty()
@ValidateNested()
@Type(() => ParticipantsValidator)
public featureFlagSegmentInclusion: ParticipantsValidator;

@IsNotEmpty()
@ValidateNested()
@Type(() => ParticipantsValidator)
public featureFlagSegmentExclusion: ParticipantsValidator;
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,34 @@ import { SORT_AS_DIRECTION } from 'upgrade_types';

// TODO: Move to upgrade types
export interface IFeatureFlagSearchParams {
key: FLAG_SEARCH_SORT_KEY;
key: FLAG_SEARCH_KEY;
string: string;
}
export interface IFeatureFlagSortParams {
key: FLAG_SEARCH_SORT_KEY;
key: FLAG_SORT_KEY;
sortAs: SORT_AS_DIRECTION;
}

export enum FLAG_SEARCH_SORT_KEY {
export enum FLAG_SORT_KEY {
NAME = 'name',
KEY = 'key',
STATUS = 'status',
UPDATED_AT = 'updatedAt',
}

export enum FLAG_SEARCH_KEY {
ALL = 'all',
NAME = 'name',
KEY = 'key',
STATUS = 'status',
VARIATION_TYPE = 'variationType',
TAG = 'tag',
CONTEXT = 'context',
}

class IFeatureFlagSortParamsValidator {
@IsNotEmpty()
@IsEnum(FLAG_SEARCH_SORT_KEY)
key: FLAG_SEARCH_SORT_KEY;
@IsEnum(FLAG_SORT_KEY)
key: FLAG_SORT_KEY;

@IsNotEmpty()
@IsEnum(SORT_AS_DIRECTION)
Expand All @@ -32,8 +40,8 @@ class IFeatureFlagSortParamsValidator {

class IFeatureFlagSearchParamsValidator {
@IsNotEmpty()
@IsEnum(FLAG_SEARCH_SORT_KEY)
key: FLAG_SEARCH_SORT_KEY;
@IsEnum(FLAG_SEARCH_KEY)
key: FLAG_SEARCH_KEY;

@IsNotEmpty()
@IsString()
Expand Down
Loading

0 comments on commit cb3e4a4

Please sign in to comment.