Skip to content

Commit

Permalink
fix up types things
Browse files Browse the repository at this point in the history
  • Loading branch information
danoswaltCL committed Dec 5, 2024
1 parent 021b412 commit 7692ea6
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ export class ValidateMoocletPolicyParametersMiddleware implements ExpressMiddlew
public async use(req: Request, res: Response, next: NextFunction): Promise<void> {
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,
Expand All @@ -27,6 +27,7 @@ export class ValidateMoocletPolicyParametersMiddleware implements ExpressMiddlew
}
}

// else, if mooclets is not enabled, keep calm and carry on
next();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -497,7 +498,7 @@ export class MoocletExperimentService extends ExperimentService {
assignmentAlgorithm: string,
moocletResponse: MoocletResponseDetails
): Promise<MoocletVariableResponseDetails> {
if (!moocletPolicyParametersResponse || assignmentAlgorithm !== SUPPORTED_MOOCLET_POLICY_NAMES.TS_CONFIGURABLE) {
if (!moocletPolicyParametersResponse || assignmentAlgorithm !== ASSIGNMENT_ALGORITHM.MOOCLET_TS_CONFIGURABLE) {
return null;
}

Expand Down
6 changes: 0 additions & 6 deletions backend/packages/Upgrade/src/types/Mooclet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ export interface MoocletPolicyResponseDetails {
environment?: string;
}

export interface MoocletDetails {
readonly mooclet?: MoocletResponseDetails;
readonly versions?: MoocletVersionResponseDetails[];
policyParameters: MoocletPolicyParameters;
}

export interface MoocletBatchResponse<T> {
count: number;
next: string;
Expand Down
File renamed without changes.
4 changes: 2 additions & 2 deletions types/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,6 @@ export {
FeatureFlagDeletedData,
} from './Experiment/interfaces';
export {
// MoocletTSConfigurablePolicyParametersDTO,
MoocletTSConfigurablePolicyParametersDTO,
MOOCLET_POLICY_SCHEMA_MAP,
} from './Mooclet/DTO';
} from './Mooclet';

0 comments on commit 7692ea6

Please sign in to comment.