-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix(api): Use the MongoId for stepId when fetching step controls #6679
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -174,12 +174,17 @@ export class BridgeController { | |||||||||||||||||||
if (!workflowExist) { | ||||||||||||||||||||
throw new NotFoundException('Workflow not found'); | ||||||||||||||||||||
} | ||||||||||||||||||||
const step = workflowExist?.steps.find((item) => item.stepId === stepId); | ||||||||||||||||||||
|
||||||||||||||||||||
if (!step || !step._id) { | ||||||||||||||||||||
throw new NotFoundException('Step not found'); | ||||||||||||||||||||
} | ||||||||||||||||||||
Comment on lines
+179
to
+181
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Question: can we do something like this?
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As discussed, we will address this holistically across the API using shared classes. |
||||||||||||||||||||
|
||||||||||||||||||||
const result = await this.controlValuesRepository.findOne({ | ||||||||||||||||||||
_environmentId: user.environmentId, | ||||||||||||||||||||
_organizationId: user.organizationId, | ||||||||||||||||||||
_workflowId: workflowExist._id, | ||||||||||||||||||||
stepId, | ||||||||||||||||||||
_stepId: step._id, | ||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This change fixes the fetching of persisted step controls. |
||||||||||||||||||||
level: ControlVariablesLevelEnum.STEP_CONTROLS, | ||||||||||||||||||||
}); | ||||||||||||||||||||
|
||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,7 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import defaults from 'json-schema-defaults'; | ||
|
||
import { Injectable, NotFoundException } from '@nestjs/common'; | ||
import { NotificationTemplateRepository } from '@novu/dal'; | ||
import { JsonSchema } from '@novu/framework'; | ||
|
||
import { ApiException, UpsertControlValuesCommand, UpsertControlValuesUseCase } from '@novu/application-generic'; | ||
import { UpsertControlValuesCommand, UpsertControlValuesUseCase } from '@novu/application-generic'; | ||
import { StoreControlVariablesCommand } from './store-control-variables.command'; | ||
|
||
@Injectable() | ||
|
@@ -21,28 +18,22 @@ export class StoreControlVariablesUseCase { | |
); | ||
|
||
if (!workflowExist) { | ||
throw new ApiException('Workflow not found'); | ||
throw new NotFoundException('Workflow not found'); | ||
} | ||
|
||
const step = workflowExist?.steps.find((item) => item.stepId === command.stepId); | ||
|
||
if (!step || !step._id) { | ||
throw new ApiException('Step not found'); | ||
throw new NotFoundException('Step not found'); | ||
} | ||
Comment on lines
+21
to
+27
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same here. |
||
|
||
const stepDefaultControls = defaults( | ||
(step.template as any)?.controls?.schema || (step.template as any)?.inputs?.schema, | ||
{} | ||
) as JsonSchema; | ||
|
||
return await this.upsertControlValuesUseCase.execute( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Defaults are generated on There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question just to clarify, for the dashboard, we need to make sure it gets the default values for the code-first solution, so it can display them. If we have a code-first preview, we first get the default values from the bridge app and then override them with control values if they exist (persisted in novu), correct? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The JSON schema from |
||
UpsertControlValuesCommand.create({ | ||
organizationId: command.organizationId, | ||
environmentId: command.environmentId, | ||
notificationStepEntity: step, | ||
workflowId: workflowExist._id, | ||
newControlValues: command.variables, | ||
controlSchemas: { schema: stepDefaultControls }, | ||
}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧹 👏 |
||
); | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export * from './upsert-control-values-command'; | ||
export * from './upsert-control-values-use-case'; | ||
export * from './upsert-control-values.command'; | ||
export * from './upsert-control-values.usecase'; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,8 @@ | ||
import { IsNotEmpty, IsObject, IsOptional, IsString } from 'class-validator'; | ||
import { JsonSchema } from '@novu/framework'; | ||
import { NotificationStepEntity } from '@novu/dal'; | ||
import { OrganizationLevelCommand } from '../../commands'; | ||
import { EnvironmentCommand } from '../../commands'; | ||
|
||
export class UpsertControlValuesCommand extends OrganizationLevelCommand { | ||
export class UpsertControlValuesCommand extends EnvironmentCommand { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The incorrect base command was used here, which resulted in |
||
@IsObject() | ||
notificationStepEntity: NotificationStepEntity; | ||
|
||
|
@@ -14,7 +13,4 @@ export class UpsertControlValuesCommand extends OrganizationLevelCommand { | |
@IsObject() | ||
@IsOptional() | ||
newControlValues?: Record<string, unknown>; | ||
|
||
@IsObject() | ||
controlSchemas: { schema: JsonSchema }; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This was never used. Cleaning up. |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,15 +2,15 @@ import { Injectable } from '@nestjs/common'; | |
|
||
import { ControlValuesEntity, ControlValuesRepository } from '@novu/dal'; | ||
import { ControlVariablesLevelEnum } from '@novu/shared'; | ||
import { UpsertControlValuesCommand } from './upsert-control-values-command'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. i am a bit confused should not it be a dot here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The new code shows a dot. |
||
import { UpsertControlValuesCommand } from './upsert-control-values.command'; | ||
|
||
@Injectable() | ||
export class UpsertControlValuesUseCase { | ||
constructor(private controlValuesRepository: ControlValuesRepository) {} | ||
|
||
async execute(command: UpsertControlValuesCommand) { | ||
const existingControlValues = await this.controlValuesRepository.findFirst({ | ||
_environmentId: command.environmentId || '', | ||
_environmentId: command.environmentId, | ||
_organizationId: command.organizationId, | ||
_workflowId: command.workflowId, | ||
_stepId: command.notificationStepEntity._templateId, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,4 @@ export class ControlValuesEntity { | |
controls: Record<string, unknown>; | ||
_workflowId: string; | ||
_stepId: string; | ||
workflowId: string; | ||
stepId: string; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. These are no longer used. |
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not needed.