Skip to content

Commit

Permalink
refactor(api, worker, application-generic, dal, shared): Rename "Cont…
Browse files Browse the repository at this point in the history
…rolVariables" to "ControlValues" (#6680)
  • Loading branch information
rifont authored Oct 14, 2024
1 parent ceec237 commit 386d6d1
Show file tree
Hide file tree
Showing 19 changed files with 58 additions and 58 deletions.
14 changes: 7 additions & 7 deletions apps/api/src/app/bridge/bridge.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ import {
UseInterceptors,
} from '@nestjs/common';

import { ControlVariablesLevelEnum, UserSessionData, WorkflowTypeEnum } from '@novu/shared';
import { ControlValuesLevelEnum, UserSessionData, WorkflowTypeEnum } from '@novu/shared';
import { AnalyticsService, ExternalApiAccessible, UserAuthGuard, UserSession } from '@novu/application-generic';
import { ControlValuesRepository, EnvironmentRepository, NotificationTemplateRepository } from '@novu/dal';

import { ApiExcludeController } from '@nestjs/swagger';

import { StoreControlVariablesCommand, StoreControlVariablesUseCase } from './usecases/store-control-variables';
import { StoreControlValuesCommand, StoreControlValuesUseCase } from './usecases/store-control-values';
import { PreviewStep, PreviewStepCommand } from './usecases/preview-step';
import { SyncCommand } from './usecases/sync';
import { Sync } from './usecases/sync/sync.usecase';
Expand All @@ -41,7 +41,7 @@ export class BridgeController {
private environmentRepository: EnvironmentRepository,
private notificationTemplateRepository: NotificationTemplateRepository,
private controlValuesRepository: ControlValuesRepository,
private storeControlVariablesUseCase: StoreControlVariablesUseCase,
private storeControlValuesUseCase: StoreControlValuesUseCase,
private previewStep: PreviewStep,
private analyticsService: AnalyticsService
) {}
Expand Down Expand Up @@ -185,7 +185,7 @@ export class BridgeController {
_organizationId: user.organizationId,
_workflowId: workflowExist._id,
_stepId: step._id,
level: ControlVariablesLevelEnum.STEP_CONTROLS,
level: ControlValuesLevelEnum.STEP_CONTROLS,
});

return result;
Expand All @@ -200,11 +200,11 @@ export class BridgeController {
@UserSession() user: UserSessionData,
@Body() body: any
) {
return this.storeControlVariablesUseCase.execute(
StoreControlVariablesCommand.create({
return this.storeControlValuesUseCase.execute(
StoreControlValuesCommand.create({
stepId,
workflowId,
variables: body.variables,
controlValues: body.variables,
environmentId: user.environmentId,
organizationId: user.organizationId,
userId: user._id,
Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/bridge/usecases/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import { UpsertControlValuesUseCase } from '@novu/application-generic';
import { DeleteWorkflow } from './delete-workflow';
import { GetBridgeStatus } from './get-bridge-status';
import { PreviewStep } from './preview-step';
import { StoreControlVariablesUseCase } from './store-control-variables';
import { StoreControlValuesUseCase } from './store-control-values';
import { Sync } from './sync';

export const USECASES = [
DeleteWorkflow,
GetBridgeStatus,
PreviewStep,
StoreControlVariablesUseCase,
StoreControlValuesUseCase,
Sync,
UpsertControlValuesUseCase,
];
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export * from './store-control-values.command';
export * from './store-control-values.usecase';
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { EnvironmentWithUserCommand } from '@novu/application-generic';

export class StoreControlValuesCommand extends EnvironmentWithUserCommand {
stepId: string;
workflowId: string;
controlValues: Record<string, unknown>;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ import { Injectable, NotFoundException } from '@nestjs/common';
import { NotificationTemplateRepository } from '@novu/dal';

import { UpsertControlValuesCommand, UpsertControlValuesUseCase } from '@novu/application-generic';
import { StoreControlVariablesCommand } from './store-control-variables.command';
import { StoreControlValuesCommand } from './store-control-values.command';

@Injectable()
export class StoreControlVariablesUseCase {
export class StoreControlValuesUseCase {
constructor(
private notificationTemplateRepository: NotificationTemplateRepository,
private upsertControlValuesUseCase: UpsertControlValuesUseCase
) {}

async execute(command: StoreControlVariablesCommand) {
async execute(command: StoreControlValuesCommand) {
const workflowExist = await this.notificationTemplateRepository.findByTriggerIdentifier(
command.environmentId,
command.workflowId
Expand All @@ -33,7 +33,7 @@ export class StoreControlVariablesUseCase {
environmentId: command.environmentId,
notificationStepEntity: step,
workflowId: workflowExist._id,
newControlValues: command.variables,
newControlValues: command.controlValues,
})
);
}
Expand Down

This file was deleted.

This file was deleted.

4 changes: 2 additions & 2 deletions apps/api/src/app/events/e2e/bridge-trigger.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,7 @@ contexts.forEach((context: Context) => {

if (context.isStateful) {
await discoverAndSyncBridge(session, workflowsRepository, workflowId, bridgeServer);
await saveControlVariables(session, workflowId, stepId, { variables: { name: 'stored_control_name' } });
await saveControlValues(session, workflowId, stepId, { variables: { name: 'stored_control_name' } });
}

const controls = { steps: { [stepId]: { name: 'stored_control_name' } } };
Expand Down Expand Up @@ -1539,7 +1539,7 @@ async function discoverAndSyncBridge(
return discoverResponse;
}

async function saveControlVariables(
async function saveControlValues(
session: UserSession,
workflowIdentifier?: string,
stepIdentifier?: string,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import {
NotificationStepEntity,
NotificationTemplateRepository,
} from '@novu/dal';
import { ControlVariablesLevelEnum, WorkflowResponseDto } from '@novu/shared';
import { ControlValuesLevelEnum, WorkflowResponseDto } from '@novu/shared';
import { GetPreferences, GetPreferencesCommand } from '@novu/application-generic';

import { GetWorkflowCommand } from './get-workflow.command';
Expand Down Expand Up @@ -64,7 +64,7 @@ export class GetWorkflowUseCase {
_organizationId: command.user.organizationId,
_workflowId: command._workflowId,
_stepId: step._templateId,
level: ControlVariablesLevelEnum.STEP_CONTROLS,
level: ControlValuesLevelEnum.STEP_CONTROLS,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
JobEntity,
} from '@novu/dal';
import {
ControlVariablesLevelEnum,
ControlValuesLevelEnum,
ExecutionDetailsSourceEnum,
ExecutionDetailsStatusEnum,
JobStatusEnum,
Expand Down Expand Up @@ -91,7 +91,7 @@ export class ExecuteBridgeJob {
const state = await this.generateState(payload, command);

const variablesStores = isStateful
? await this.findControlVariables(command, workflow as NotificationTemplateEntity)
? await this.findControlValues(command, workflow as NotificationTemplateEntity)
: command.job.step.controlVariables;

const bridgeEvent: Omit<Event, 'workflowId' | 'stepId' | 'action'> = {
Expand Down Expand Up @@ -134,12 +134,12 @@ export class ExecuteBridgeJob {
return bridgeResponse;
}

private async findControlVariables(command: ExecuteBridgeJobCommand, workflow: NotificationTemplateEntity) {
private async findControlValues(command: ExecuteBridgeJobCommand, workflow: NotificationTemplateEntity) {
const controls = await this.controlValuesRepository.findOne({
_organizationId: command.organizationId,
_workflowId: workflow._id,
_stepId: command.job.step._id,
level: ControlVariablesLevelEnum.STEP_CONTROLS,
level: ControlValuesLevelEnum.STEP_CONTROLS,
});

return controls?.controls || controls?.inputs;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Injectable } from '@nestjs/common';

import { ControlValuesEntity, ControlValuesRepository } from '@novu/dal';
import { ControlVariablesLevelEnum } from '@novu/shared';
import { ControlValuesLevelEnum } from '@novu/shared';
import { UpsertControlValuesCommand } from './upsert-control-values.command';

@Injectable()
Expand All @@ -14,11 +14,11 @@ export class UpsertControlValuesUseCase {
_organizationId: command.organizationId,
_workflowId: command.workflowId,
_stepId: command.notificationStepEntity._templateId,
level: ControlVariablesLevelEnum.STEP_CONTROLS,
level: ControlValuesLevelEnum.STEP_CONTROLS,
});

if (existingControlValues) {
return await this.updateControlVariables(
return await this.updateControlValues(
existingControlValues,
command,
command.newControlValues,
Expand All @@ -30,14 +30,14 @@ export class UpsertControlValuesUseCase {
_environmentId: command.environmentId,
_workflowId: command.workflowId,
_stepId: command.notificationStepEntity._templateId,
level: ControlVariablesLevelEnum.STEP_CONTROLS,
level: ControlValuesLevelEnum.STEP_CONTROLS,
priority: 0,
inputs: command.newControlValues,
controls: command.newControlValues,
});
}

private async updateControlVariables(
private async updateControlValues(
found: ControlValuesEntity,
command: UpsertControlValuesCommand,
controlValues: Record<string, unknown>,
Expand Down
2 changes: 1 addition & 1 deletion libs/dal/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,6 @@ export * from './repositories/workflow-override';
export * from './shared';
export * from './repositories/base-repository';
export * from './repositories/schema-default.options';
export * from './repositories/control-variables';
export * from './repositories/control-values';
export * from './repositories/preferences';
export * from './types';
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
import { ControlVariablesLevelEnum } from '@novu/shared';
import { ControlValuesLevelEnum } from '@novu/shared';

export class ControlValuesEntity {
_id: string;
createdAt: string;
updatedAt: string;
_environmentId: string;
_organizationId: string;
level: ControlVariablesLevelEnum;
level: ControlValuesLevelEnum;
priority: number;
inputs: Record<string, unknown>;
controls: Record<string, unknown>;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { SoftDeleteModel } from 'mongoose-delete';
import { ControlVariablesLevelEnum } from '@novu/shared';
import { ControlValuesModel, ControlVariables } from './controlVariables.schema';
import { ControlValuesEntity } from './controlValuesEntity';
import { ControlValuesLevelEnum } from '@novu/shared';
import { ControlValuesModel, ControlValues } from './control-values.schema';
import { ControlValuesEntity } from './control-values.entity';
import { BaseRepository } from '../base-repository';
import { EnforceEnvOrOrgIds } from '../../types';

Expand All @@ -11,7 +11,7 @@ export interface DeleteManyValuesQuery {
_organizationId: string;
_workflowId: string;
_stepId?: string;
level?: ControlVariablesLevelEnum;
level?: ControlValuesLevelEnum;
}

// eslint-disable-next-line @typescript-eslint/naming-convention
Expand All @@ -20,19 +20,19 @@ export interface FindControlValuesQuery {
_organizationId: string;
_workflowId: string;
_stepId: string;
level?: ControlVariablesLevelEnum;
level?: ControlValuesLevelEnum;
}

export class ControlValuesRepository extends BaseRepository<
ControlValuesModel,
ControlValuesEntity,
EnforceEnvOrOrgIds
> {
private controlVariables: SoftDeleteModel;
private controlValues: SoftDeleteModel;

constructor() {
super(ControlVariables, ControlValuesEntity);
this.controlVariables = ControlVariables;
super(ControlValues, ControlValuesEntity);
this.controlValues = ControlValues;
}

async deleteMany(query: DeleteManyValuesQuery) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import mongoose, { Schema } from 'mongoose';
import { ChangePropsValueType } from '../../types';
import { schemaOptions } from '../schema-default.options';
import { ControlValuesEntity } from './controlValuesEntity';
import { ControlValuesEntity } from './control-values.entity';

const mongooseDelete = require('mongoose-delete');

Expand All @@ -10,7 +10,7 @@ export type ControlValuesModel = ChangePropsValueType<
'_environmentId' | '_organizationId' | '_workflowId'
>;

const controlVariablesSchema = new Schema<ControlValuesModel>(
const controlValuesSchema = new Schema<ControlValuesModel>(
{
_environmentId: {
type: Schema.Types.ObjectId,
Expand All @@ -37,9 +37,9 @@ const controlVariablesSchema = new Schema<ControlValuesModel>(
schemaOptions
);

controlVariablesSchema.plugin(mongooseDelete, { deletedAt: true, deletedBy: true, overrideMethods: 'all' });
controlValuesSchema.plugin(mongooseDelete, { deletedAt: true, deletedBy: true, overrideMethods: 'all' });

export const ControlVariables =
(mongoose.models.ControlVariables as mongoose.Model<ControlValuesModel>) ||
mongoose.model<ControlValuesModel>('controls', controlVariablesSchema) ||
mongoose.model<ControlValuesModel>('inputs', controlVariablesSchema);
export const ControlValues =
(mongoose.models.ControlValues as mongoose.Model<ControlValuesModel>) ||
mongoose.model<ControlValuesModel>('controls', controlValuesSchema) ||
mongoose.model<ControlValuesModel>('inputs', controlValuesSchema);
3 changes: 3 additions & 0 deletions libs/dal/src/repositories/control-values/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export * from './control-values.entity';
export * from './control-values.schema';
export * from './control-values.repository';
3 changes: 0 additions & 3 deletions libs/dal/src/repositories/control-variables/index.ts

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export enum ControlVariablesLevelEnum {
export enum ControlValuesLevelEnum {
WORKFLOW_CONTROLS = 'workflow',
STEP_CONTROLS = 'step',
}
2 changes: 1 addition & 1 deletion packages/shared/src/types/controls/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './control-variables-level.enum';
export * from './control-values-level.enum';

0 comments on commit 386d6d1

Please sign in to comment.