-
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
fix(api): Use the MongoId for stepId when fetching step controls #6679
Conversation
✅ Deploy Preview for novu-stg-vite-dashboard-poc ready!
To edit notification comments on pull requests, go to your Netlify site configuration. |
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
These are no longer used.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
This was never used. Cleaning up.
|
||
export class UpsertControlValuesCommand extends OrganizationLevelCommand { | ||
export class UpsertControlValuesCommand extends EnvironmentCommand { |
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.
The incorrect base command was used here, which resulted in environmentId
being an optional type when it should have been required.
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'; |
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.
Fixing to follow naming conventions.
(step.template as any)?.controls?.schema || (step.template as any)?.inputs?.schema, | ||
{} | ||
) as JsonSchema; | ||
|
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.
Defaults are generated on @novu/framework
, there is no need to generate defaults on the API.
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
The JSON schema from @novu/framework
is passed to the frontend to render the default values, so we don't need to create defaults on the API.
|
||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
This change fixes the fetching of persisted step controls.
@@ -71,7 +71,6 @@ | |||
"helmet": "^6.0.1", | |||
"i18next": "^23.7.6", | |||
"ioredis": "5.3.2", | |||
"json-schema-defaults": "^0.4.0", |
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.
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.
awesome work, left couple of comments for your consideration
if (!step || !step._id) { | ||
throw new NotFoundException('Step not found'); | ||
} |
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.
Question: can we do something like this?
I started to use this pattern in this PR this way we have the clean message to search by with the additional metadata (step id)
if (!step || !step._id) { | |
throw new NotFoundException('Step not found'); | |
} | |
if (!step || !step._id) { | |
throw new NotFoundException({ | |
message: 'Step not found', | |
stepId: stepId, | |
}); | |
} |
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.
As discussed, we will address this holistically across the API using shared classes.
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'); |
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.
same here.
(step.template as any)?.controls?.schema || (step.template as any)?.inputs?.schema, | ||
{} | ||
) as JsonSchema; | ||
|
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.
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?
return await this.upsertControlValuesUseCase.execute( | ||
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 comment
The reason will be displayed to describe this comment to others. Learn more.
🧹 👏
@@ -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 comment
The 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 comment
The reason will be displayed to describe this comment to others. Learn more.
The new code shows a dot.
What changed? Why was the change needed?
stepId
was used when fetching step controls. A recent PR removed persistence ofstepId
, this causednull
to always be returned when fetching step controls from the Dashboard, meaning that the default controls were always showncontrolSchema
property fromUpsertControlValues
use-casejson-schema-defaults
package from API which is redundant -@novu/framework
already generates the defaultsworkflowId
andstepId
properties fromControlValuesEntity
Screenshots
persisted-controls-fetching.mov
Expand for optional sections
Related enterprise PR
Special notes for your reviewer