diff --git a/backend/packages/Upgrade/src/api/middlewares/ValidateMoocletPolicyParameters.ts b/backend/packages/Upgrade/src/api/middlewares/ValidateMoocletPolicyParameters.ts index f73468e747..11d6717cc2 100644 --- a/backend/packages/Upgrade/src/api/middlewares/ValidateMoocletPolicyParameters.ts +++ b/backend/packages/Upgrade/src/api/middlewares/ValidateMoocletPolicyParameters.ts @@ -9,13 +9,13 @@ export class ValidateMoocletPolicyParametersMiddleware implements ExpressMiddlew public async use(req: Request, res: Response, next: NextFunction): Promise { const experiment = req.body; - if (!env.mooclets.enabled && 'moocletPolicyParameters' in experiment) { + if (!env.mooclets?.enabled && 'moocletPolicyParameters' in experiment) { throw new UnprocessableEntityException( 'Failed to create Experiment: moocletPolicyParameters was provided but mooclets are not enabled on backend.' ); } - - if (env.mooclets.enabled) { + + if (env.mooclets?.enabled) { try { const policyParameters = await validateMoocletPolicyParameters( experiment.assignmentAlgorithm, @@ -27,6 +27,7 @@ export class ValidateMoocletPolicyParametersMiddleware implements ExpressMiddlew } } + // else, if mooclets is not enabled, keep calm and carry on next(); } } \ No newline at end of file diff --git a/backend/packages/Upgrade/src/api/services/MoocletExperimentService.ts b/backend/packages/Upgrade/src/api/services/MoocletExperimentService.ts index 9d905c325c..34602996a4 100644 --- a/backend/packages/Upgrade/src/api/services/MoocletExperimentService.ts +++ b/backend/packages/Upgrade/src/api/services/MoocletExperimentService.ts @@ -11,7 +11,6 @@ import { MoocletVersionRequestBody, MoocletVersionResponseDetails, } from '../../types/Mooclet'; -import { SUPPORTED_MOOCLET_POLICY_NAMES } from 'upgrade_types'; import { ExperimentService } from './ExperimentService'; import { ExperimentRepository } from '../repositories/ExperimentRepository'; import { ExperimentConditionRepository } from '../repositories/ExperimentConditionRepository'; @@ -50,6 +49,7 @@ import { ConditionValidator } from '../DTO/ExperimentDTO'; import { UserDTO } from '../DTO/UserDTO'; import { Experiment } from '../models/Experiment'; import { UpgradeLogger } from '../../lib/logger/UpgradeLogger'; +import { ASSIGNMENT_ALGORITHM } from 'types/src'; export interface SyncCreateParams { experimentDTO: MoocletExperimentDTO; @@ -309,6 +309,7 @@ export class MoocletExperimentService extends ExperimentService { }); moocletExperimentRef.variableId = moocletVariableResponse?.id; } catch (err) { + console.log('>>>>>>>>>>>>>>> mooclet creation error, roll back', err) await this.handleMoocletCreationError(err, moocletExperimentRef, logger); } @@ -497,7 +498,7 @@ export class MoocletExperimentService extends ExperimentService { assignmentAlgorithm: string, moocletResponse: MoocletResponseDetails ): Promise { - if (!moocletPolicyParametersResponse || assignmentAlgorithm !== SUPPORTED_MOOCLET_POLICY_NAMES.TS_CONFIGURABLE) { + if (!moocletPolicyParametersResponse || assignmentAlgorithm !== ASSIGNMENT_ALGORITHM.MOOCLET_TS_CONFIGURABLE) { return null; } diff --git a/backend/packages/Upgrade/src/types/Mooclet.ts b/backend/packages/Upgrade/src/types/Mooclet.ts index 85c0e31d53..bfd7bc6eb5 100644 --- a/backend/packages/Upgrade/src/types/Mooclet.ts +++ b/backend/packages/Upgrade/src/types/Mooclet.ts @@ -115,12 +115,6 @@ export interface MoocletPolicyResponseDetails { environment?: string; } -export interface MoocletDetails { - readonly mooclet?: MoocletResponseDetails; - readonly versions?: MoocletVersionResponseDetails[]; - policyParameters: MoocletPolicyParameters; -} - export interface MoocletBatchResponse { count: number; next: string; diff --git a/types/src/Mooclet/DTO.ts b/types/src/Mooclet/index.ts similarity index 100% rename from types/src/Mooclet/DTO.ts rename to types/src/Mooclet/index.ts diff --git a/types/src/index.ts b/types/src/index.ts index 70c803a628..f294d03fd7 100644 --- a/types/src/index.ts +++ b/types/src/index.ts @@ -77,6 +77,6 @@ export { FeatureFlagDeletedData, } from './Experiment/interfaces'; export { - // MoocletTSConfigurablePolicyParametersDTO, + MoocletTSConfigurablePolicyParametersDTO, MOOCLET_POLICY_SCHEMA_MAP, -} from './Mooclet/DTO'; \ No newline at end of file +} from './Mooclet'; \ No newline at end of file