From d15751ad2b982368dca7de4b9e70c5cae30f425f Mon Sep 17 00:00:00 2001 From: GalT <39020298+tatarco@users.noreply.github.com> Date: Tue, 12 Nov 2024 12:56:08 +0100 Subject: [PATCH] bug(api): WIP --- .../generate-preview/generate-preview.usecase.ts | 8 +++++--- .../validate-placeholder-use.case.ts | 12 ++++++++---- .../generate-preview/validate-placeholder.command.ts | 3 ++- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts b/apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts index 72dcebe6a757..e61edd9a438c 100644 --- a/apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts +++ b/apps/api/src/app/workflows-v2/usecases/generate-preview/generate-preview.usecase.ts @@ -10,8 +10,8 @@ import { StepTypeEnum, } from '@novu/shared'; import { merge } from 'lodash/fp'; +import { undefined } from 'zod'; import _ = require('lodash'); -import { GetWorkflowByIdsUseCase } from '@novu/application-generic'; import { GeneratePreviewCommand } from './generate-preview-command'; import { PreviewStep, PreviewStepCommand } from '../../../bridge/usecases/preview-step'; import { BuildDefaultPayloadUseCase } from '../build-payload-from-placeholder'; @@ -20,6 +20,7 @@ import { ValidateControlValuesAndConstructPassableStructureUsecase } from '../va import { GetStepDataUsecase } from '../get-step-schema/get-step-data.usecase'; import { CollectPlaceholderWithDefaultsUsecase } from '../collect-placeholders/collect-placeholder-with-defaults.usecase'; import { ValidatePlaceholderUseCase } from './validate-placeholder-use.case'; +import { StepMissingControlsException, StepNotFoundException } from '../../exceptions/step-not-found-exception'; @Injectable() export class GeneratePreviewUsecase { @@ -38,8 +39,9 @@ export class GeneratePreviewUsecase { const controlValueToPlaceholders = this.collectPlaceholderWithDefaultsUsecase.execute({ controlValues: dto.controlValues, }); - this.validatePlaceholdersUseCase.execute({ - controlValueToPlaceholders: { controlValueToPlaceholders, variableSchema: stepData.variables }, + const controlValueToValidPlaceholders = this.validatePlaceholdersUseCase.execute({ + controlValueToPlaceholders, + variableSchema: stepData.variables, }); const { previewPayload, issues } = this.constructPayloadUseCase.execute({ controlValues: dto.controlValues, diff --git a/apps/api/src/app/workflows-v2/usecases/generate-preview/validate-placeholder-use.case.ts b/apps/api/src/app/workflows-v2/usecases/generate-preview/validate-placeholder-use.case.ts index ad5e6cb444b9..af9f3ff98107 100644 --- a/apps/api/src/app/workflows-v2/usecases/generate-preview/validate-placeholder-use.case.ts +++ b/apps/api/src/app/workflows-v2/usecases/generate-preview/validate-placeholder-use.case.ts @@ -19,7 +19,7 @@ export class ValidatePlaceholderUseCase { placeholderAggregation: PlaceholderAggregation, variableSchema: Record ): ValidatedPlaceholderAggregation { - const { problematic, validPlacholders } = this.validateRegularPlaceholders( + const { problematic, validPlaceholders } = this.validateRegularPlaceholders( placeholderAggregation.regularPlaceholdersToDefaultValue, variableSchema ); @@ -31,7 +31,7 @@ export class ValidatePlaceholderUseCase { return { problematicPlaceholders: [...problematic, ...problematicNested], validNestedForPlaceholders: validNestedPlacholders, - validRegularPlaceholdersToDefaultValue: validPlacholders, + validRegularPlaceholdersToDefaultValue: validPlaceholders, }; } @@ -42,13 +42,17 @@ export class ValidatePlaceholderUseCase { const problematic: string[] = []; const validPlacholdersToDefaultValueMap: Record = {}; for (const placeholder of Object.keys(regularPlaceholdersToDefaultValue)) { - if (variableSchema[placeholder]) { + if (this.isPlaceholderValid(variableSchema, placeholder)) { validPlacholdersToDefaultValueMap[placeholder] = regularPlaceholdersToDefaultValue[placeholder]; } else { problematic.push(placeholder); } } - return { problematic, validPlacholders }; + return { problematic, validPlaceholders: validPlacholders }; + } + + private isPlaceholderValid(variableSchema: Record, placeholder: string) { + return variableSchema[placeholder]; } } diff --git a/apps/api/src/app/workflows-v2/usecases/generate-preview/validate-placeholder.command.ts b/apps/api/src/app/workflows-v2/usecases/generate-preview/validate-placeholder.command.ts index db8f857172d8..3702c5eb0acb 100644 --- a/apps/api/src/app/workflows-v2/usecases/generate-preview/validate-placeholder.command.ts +++ b/apps/api/src/app/workflows-v2/usecases/generate-preview/validate-placeholder.command.ts @@ -1,7 +1,8 @@ +import { JSONSchemaDto } from '@novu/shared'; import { PlaceholderAggregation } from '../collect-placeholders/placeholder.aggregation'; // eslint-disable-next-line @typescript-eslint/naming-convention export interface ValidatePlaceholderCommand { controlValueToPlaceholders: Record; - variableSchema: Record; + variableSchema: JSONSchemaDto; }