Skip to content

Commit

Permalink
fix(api): Don't create Workflow Preferences when preferences doesn'…
Browse files Browse the repository at this point in the history
…t exist during sync (#6486)
  • Loading branch information
rifont authored Sep 11, 2024
1 parent b2f58d3 commit 9f3bcf2
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions apps/api/src/app/bridge/usecases/sync/sync.usecase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ import {
ExecuteBridgeRequest,
UpsertPreferences,
UpsertWorkflowPreferencesCommand,
GetFeatureFlag,
GetFeatureFlagCommand,
} from '@novu/application-generic';
import { WorkflowTypeEnum } from '@novu/shared';
import { FeatureFlagsKeysEnum, WorkflowTypeEnum } from '@novu/shared';
import { DiscoverOutput, DiscoverStepOutput, DiscoverWorkflowOutput, GetActionEnum } from '@novu/framework';

import { SyncCommand } from './sync.command';
Expand All @@ -36,7 +38,8 @@ export class Sync {
private environmentRepository: EnvironmentRepository,
private executeBridgeRequest: ExecuteBridgeRequest,
private analyticsService: AnalyticsService,
private upsertPreferences: UpsertPreferences
private upsertPreferences: UpsertPreferences,
private getFeatureFlag: GetFeatureFlag
) {}
async execute(command: SyncCommand): Promise<CreateBridgeResponseDto> {
const environment = await this.environmentRepository.findOne({ _id: command.environmentId });
Expand Down Expand Up @@ -204,15 +207,26 @@ export class Sync {
);
}

await this.upsertPreferences.upsertWorkflowPreferences(
UpsertWorkflowPreferencesCommand.create({
environmentId: savedWorkflow._environmentId,
organizationId: savedWorkflow._organizationId,
templateId: savedWorkflow._id,
preferences: workflow.preferences,
const isWorkflowPreferencesEnabled = await this.getFeatureFlag.execute(
GetFeatureFlagCommand.create({
key: FeatureFlagsKeysEnum.IS_WORKFLOW_PREFERENCES_ENABLED,
environmentId: command.environmentId,
organizationId: command.organizationId,
userId: command.userId,
})
);

if (isWorkflowPreferencesEnabled && workflow.preferences) {
await this.upsertPreferences.upsertWorkflowPreferences(
UpsertWorkflowPreferencesCommand.create({
environmentId: savedWorkflow._environmentId,
organizationId: savedWorkflow._organizationId,
templateId: savedWorkflow._id,
preferences: workflow.preferences,
})
);
}

return savedWorkflow;
})
);
Expand Down

0 comments on commit 9f3bcf2

Please sign in to comment.