From 386d6d15901ca3495f4edf5fa616f02c1f23f66f Mon Sep 17 00:00:00 2001 From: Richard Fontein <32132657+rifont@users.noreply.github.com> Date: Mon, 14 Oct 2024 12:14:27 +0200 Subject: [PATCH] refactor(api, worker, application-generic, dal, shared): Rename "ControlVariables" to "ControlValues" (#6680) --- apps/api/src/app/bridge/bridge.controller.ts | 14 +++++++------- apps/api/src/app/bridge/usecases/index.ts | 4 ++-- .../usecases/store-control-values/index.ts | 2 ++ .../store-control-values.command.ts | 7 +++++++ .../store-control-values.usecase.ts} | 8 ++++---- .../usecases/store-control-variables/index.ts | 2 -- .../store-control-variables.command.ts | 7 ------- .../api/src/app/events/e2e/bridge-trigger.e2e.ts | 4 ++-- .../get-workflow/get-workflow.usecase.ts | 4 ++-- .../execute-bridge-job.usecase.ts | 8 ++++---- .../upsert-control-values.usecase.ts | 10 +++++----- libs/dal/src/index.ts | 2 +- .../control-values.entity.ts} | 4 ++-- .../control-values.repository.ts} | 16 ++++++++-------- .../control-values.schema.ts} | 14 +++++++------- .../dal/src/repositories/control-values/index.ts | 3 +++ .../src/repositories/control-variables/index.ts | 3 --- ...evel.enum.ts => control-values-level.enum.ts} | 2 +- packages/shared/src/types/controls/index.ts | 2 +- 19 files changed, 58 insertions(+), 58 deletions(-) create mode 100644 apps/api/src/app/bridge/usecases/store-control-values/index.ts create mode 100644 apps/api/src/app/bridge/usecases/store-control-values/store-control-values.command.ts rename apps/api/src/app/bridge/usecases/{store-control-variables/store-control-variables.usecase.ts => store-control-values/store-control-values.usecase.ts} (83%) delete mode 100644 apps/api/src/app/bridge/usecases/store-control-variables/index.ts delete mode 100644 apps/api/src/app/bridge/usecases/store-control-variables/store-control-variables.command.ts rename libs/dal/src/repositories/{control-variables/controlValuesEntity.ts => control-values/control-values.entity.ts} (75%) rename libs/dal/src/repositories/{control-variables/controlValuesRepository.ts => control-values/control-values.repository.ts} (71%) rename libs/dal/src/repositories/{control-variables/controlVariables.schema.ts => control-values/control-values.schema.ts} (64%) create mode 100644 libs/dal/src/repositories/control-values/index.ts delete mode 100644 libs/dal/src/repositories/control-variables/index.ts rename packages/shared/src/types/controls/{control-variables-level.enum.ts => control-values-level.enum.ts} (60%) diff --git a/apps/api/src/app/bridge/bridge.controller.ts b/apps/api/src/app/bridge/bridge.controller.ts index 421615675e4..526d125eb5b 100644 --- a/apps/api/src/app/bridge/bridge.controller.ts +++ b/apps/api/src/app/bridge/bridge.controller.ts @@ -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'; @@ -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 ) {} @@ -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; @@ -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, diff --git a/apps/api/src/app/bridge/usecases/index.ts b/apps/api/src/app/bridge/usecases/index.ts index 1ec761cb7ac..fd739b87184 100644 --- a/apps/api/src/app/bridge/usecases/index.ts +++ b/apps/api/src/app/bridge/usecases/index.ts @@ -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, ]; diff --git a/apps/api/src/app/bridge/usecases/store-control-values/index.ts b/apps/api/src/app/bridge/usecases/store-control-values/index.ts new file mode 100644 index 00000000000..c7e3e89333c --- /dev/null +++ b/apps/api/src/app/bridge/usecases/store-control-values/index.ts @@ -0,0 +1,2 @@ +export * from './store-control-values.command'; +export * from './store-control-values.usecase'; diff --git a/apps/api/src/app/bridge/usecases/store-control-values/store-control-values.command.ts b/apps/api/src/app/bridge/usecases/store-control-values/store-control-values.command.ts new file mode 100644 index 00000000000..5e81cca1256 --- /dev/null +++ b/apps/api/src/app/bridge/usecases/store-control-values/store-control-values.command.ts @@ -0,0 +1,7 @@ +import { EnvironmentWithUserCommand } from '@novu/application-generic'; + +export class StoreControlValuesCommand extends EnvironmentWithUserCommand { + stepId: string; + workflowId: string; + controlValues: Record; +} diff --git a/apps/api/src/app/bridge/usecases/store-control-variables/store-control-variables.usecase.ts b/apps/api/src/app/bridge/usecases/store-control-values/store-control-values.usecase.ts similarity index 83% rename from apps/api/src/app/bridge/usecases/store-control-variables/store-control-variables.usecase.ts rename to apps/api/src/app/bridge/usecases/store-control-values/store-control-values.usecase.ts index 0573827a2e8..b2d564c246a 100644 --- a/apps/api/src/app/bridge/usecases/store-control-variables/store-control-variables.usecase.ts +++ b/apps/api/src/app/bridge/usecases/store-control-values/store-control-values.usecase.ts @@ -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 @@ -33,7 +33,7 @@ export class StoreControlVariablesUseCase { environmentId: command.environmentId, notificationStepEntity: step, workflowId: workflowExist._id, - newControlValues: command.variables, + newControlValues: command.controlValues, }) ); } diff --git a/apps/api/src/app/bridge/usecases/store-control-variables/index.ts b/apps/api/src/app/bridge/usecases/store-control-variables/index.ts deleted file mode 100644 index d3e167d84a8..00000000000 --- a/apps/api/src/app/bridge/usecases/store-control-variables/index.ts +++ /dev/null @@ -1,2 +0,0 @@ -export * from './store-control-variables.command'; -export * from './store-control-variables.usecase'; diff --git a/apps/api/src/app/bridge/usecases/store-control-variables/store-control-variables.command.ts b/apps/api/src/app/bridge/usecases/store-control-variables/store-control-variables.command.ts deleted file mode 100644 index 74a141f8b54..00000000000 --- a/apps/api/src/app/bridge/usecases/store-control-variables/store-control-variables.command.ts +++ /dev/null @@ -1,7 +0,0 @@ -import { EnvironmentWithUserCommand } from '@novu/application-generic'; - -export class StoreControlVariablesCommand extends EnvironmentWithUserCommand { - stepId: string; - workflowId: string; - variables: Record; -} diff --git a/apps/api/src/app/events/e2e/bridge-trigger.e2e.ts b/apps/api/src/app/events/e2e/bridge-trigger.e2e.ts index ee126768417..844d80d6d80 100644 --- a/apps/api/src/app/events/e2e/bridge-trigger.e2e.ts +++ b/apps/api/src/app/events/e2e/bridge-trigger.e2e.ts @@ -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' } } }; @@ -1539,7 +1539,7 @@ async function discoverAndSyncBridge( return discoverResponse; } -async function saveControlVariables( +async function saveControlValues( session: UserSession, workflowIdentifier?: string, stepIdentifier?: string, diff --git a/apps/api/src/app/workflows-v2/usecases/get-workflow/get-workflow.usecase.ts b/apps/api/src/app/workflows-v2/usecases/get-workflow/get-workflow.usecase.ts index f2d391090f2..251ef403cc3 100644 --- a/apps/api/src/app/workflows-v2/usecases/get-workflow/get-workflow.usecase.ts +++ b/apps/api/src/app/workflows-v2/usecases/get-workflow/get-workflow.usecase.ts @@ -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'; @@ -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, }); } } diff --git a/apps/worker/src/app/workflow/usecases/execute-bridge-job/execute-bridge-job.usecase.ts b/apps/worker/src/app/workflow/usecases/execute-bridge-job/execute-bridge-job.usecase.ts index 74977407309..45c99bc7264 100644 --- a/apps/worker/src/app/workflow/usecases/execute-bridge-job/execute-bridge-job.usecase.ts +++ b/apps/worker/src/app/workflow/usecases/execute-bridge-job/execute-bridge-job.usecase.ts @@ -10,7 +10,7 @@ import { JobEntity, } from '@novu/dal'; import { - ControlVariablesLevelEnum, + ControlValuesLevelEnum, ExecutionDetailsSourceEnum, ExecutionDetailsStatusEnum, JobStatusEnum, @@ -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 = { @@ -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; diff --git a/libs/application-generic/src/usecases/upsert-control-values/upsert-control-values.usecase.ts b/libs/application-generic/src/usecases/upsert-control-values/upsert-control-values.usecase.ts index 93c27d12cc9..fc2df6af611 100644 --- a/libs/application-generic/src/usecases/upsert-control-values/upsert-control-values.usecase.ts +++ b/libs/application-generic/src/usecases/upsert-control-values/upsert-control-values.usecase.ts @@ -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() @@ -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, @@ -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, diff --git a/libs/dal/src/index.ts b/libs/dal/src/index.ts index 20af701fd07..8436409a556 100644 --- a/libs/dal/src/index.ts +++ b/libs/dal/src/index.ts @@ -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'; diff --git a/libs/dal/src/repositories/control-variables/controlValuesEntity.ts b/libs/dal/src/repositories/control-values/control-values.entity.ts similarity index 75% rename from libs/dal/src/repositories/control-variables/controlValuesEntity.ts rename to libs/dal/src/repositories/control-values/control-values.entity.ts index 1f35b46d040..b4edafe3dbd 100644 --- a/libs/dal/src/repositories/control-variables/controlValuesEntity.ts +++ b/libs/dal/src/repositories/control-values/control-values.entity.ts @@ -1,4 +1,4 @@ -import { ControlVariablesLevelEnum } from '@novu/shared'; +import { ControlValuesLevelEnum } from '@novu/shared'; export class ControlValuesEntity { _id: string; @@ -6,7 +6,7 @@ export class ControlValuesEntity { updatedAt: string; _environmentId: string; _organizationId: string; - level: ControlVariablesLevelEnum; + level: ControlValuesLevelEnum; priority: number; inputs: Record; controls: Record; diff --git a/libs/dal/src/repositories/control-variables/controlValuesRepository.ts b/libs/dal/src/repositories/control-values/control-values.repository.ts similarity index 71% rename from libs/dal/src/repositories/control-variables/controlValuesRepository.ts rename to libs/dal/src/repositories/control-values/control-values.repository.ts index 6c716f3d740..73156d7b3e6 100644 --- a/libs/dal/src/repositories/control-variables/controlValuesRepository.ts +++ b/libs/dal/src/repositories/control-values/control-values.repository.ts @@ -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'; @@ -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 @@ -20,7 +20,7 @@ export interface FindControlValuesQuery { _organizationId: string; _workflowId: string; _stepId: string; - level?: ControlVariablesLevelEnum; + level?: ControlValuesLevelEnum; } export class ControlValuesRepository extends BaseRepository< @@ -28,11 +28,11 @@ export class ControlValuesRepository extends BaseRepository< 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) { diff --git a/libs/dal/src/repositories/control-variables/controlVariables.schema.ts b/libs/dal/src/repositories/control-values/control-values.schema.ts similarity index 64% rename from libs/dal/src/repositories/control-variables/controlVariables.schema.ts rename to libs/dal/src/repositories/control-values/control-values.schema.ts index 7b17cea9524..89eab0ba62c 100644 --- a/libs/dal/src/repositories/control-variables/controlVariables.schema.ts +++ b/libs/dal/src/repositories/control-values/control-values.schema.ts @@ -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'); @@ -10,7 +10,7 @@ export type ControlValuesModel = ChangePropsValueType< '_environmentId' | '_organizationId' | '_workflowId' >; -const controlVariablesSchema = new Schema( +const controlValuesSchema = new Schema( { _environmentId: { type: Schema.Types.ObjectId, @@ -37,9 +37,9 @@ const controlVariablesSchema = new Schema( 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) || - mongoose.model('controls', controlVariablesSchema) || - mongoose.model('inputs', controlVariablesSchema); +export const ControlValues = + (mongoose.models.ControlValues as mongoose.Model) || + mongoose.model('controls', controlValuesSchema) || + mongoose.model('inputs', controlValuesSchema); diff --git a/libs/dal/src/repositories/control-values/index.ts b/libs/dal/src/repositories/control-values/index.ts new file mode 100644 index 00000000000..a1a99e1f4b7 --- /dev/null +++ b/libs/dal/src/repositories/control-values/index.ts @@ -0,0 +1,3 @@ +export * from './control-values.entity'; +export * from './control-values.schema'; +export * from './control-values.repository'; diff --git a/libs/dal/src/repositories/control-variables/index.ts b/libs/dal/src/repositories/control-variables/index.ts deleted file mode 100644 index 2d17e19095b..00000000000 --- a/libs/dal/src/repositories/control-variables/index.ts +++ /dev/null @@ -1,3 +0,0 @@ -export * from './controlValuesEntity'; -export * from './controlVariables.schema'; -export * from './controlValuesRepository'; diff --git a/packages/shared/src/types/controls/control-variables-level.enum.ts b/packages/shared/src/types/controls/control-values-level.enum.ts similarity index 60% rename from packages/shared/src/types/controls/control-variables-level.enum.ts rename to packages/shared/src/types/controls/control-values-level.enum.ts index 861163c8a36..365db46ff1f 100644 --- a/packages/shared/src/types/controls/control-variables-level.enum.ts +++ b/packages/shared/src/types/controls/control-values-level.enum.ts @@ -1,4 +1,4 @@ -export enum ControlVariablesLevelEnum { +export enum ControlValuesLevelEnum { WORKFLOW_CONTROLS = 'workflow', STEP_CONTROLS = 'step', } diff --git a/packages/shared/src/types/controls/index.ts b/packages/shared/src/types/controls/index.ts index 384a81b755d..f917e0b6ce3 100644 --- a/packages/shared/src/types/controls/index.ts +++ b/packages/shared/src/types/controls/index.ts @@ -1 +1 @@ -export * from './control-variables-level.enum'; +export * from './control-values-level.enum';