diff --git a/apps/api/src/app/workflows-v2/usecases/upsert-workflow/upsert-workflow.usecase.ts b/apps/api/src/app/workflows-v2/usecases/upsert-workflow/upsert-workflow.usecase.ts index d31a30094db..12d3e67fa6e 100644 --- a/apps/api/src/app/workflows-v2/usecases/upsert-workflow/upsert-workflow.usecase.ts +++ b/apps/api/src/app/workflows-v2/usecases/upsert-workflow/upsert-workflow.usecase.ts @@ -152,10 +152,7 @@ export class UpsertWorkflowUseCase { ); } - private async upsertUserWorkflowPreferences( - workflow: NotificationTemplateEntity, - command: UpsertWorkflowCommand - ): Promise<PreferencesEntity> { + private async upsertUserWorkflowPreferences(workflow: NotificationTemplateEntity, command: UpsertWorkflowCommand) { let preferences: WorkflowPreferences | null; if (command.workflowDto.preferences?.user !== undefined) { preferences = command.workflowDto.preferences.user; @@ -163,7 +160,7 @@ export class UpsertWorkflowUseCase { preferences = DEFAULT_WORKFLOW_PREFERENCES; } - return await this.upsertPreferencesUsecase.upsertUserWorkflowPreferences( + await this.upsertPreferencesUsecase.upsertUserWorkflowPreferences( UpsertUserWorkflowPreferencesCommand.create({ environmentId: workflow._environmentId, organizationId: workflow._organizationId, @@ -174,11 +171,8 @@ export class UpsertWorkflowUseCase { ); } - private async upsertWorkflowPreferences( - workflow: NotificationTemplateEntity, - command: UpsertWorkflowCommand - ): Promise<PreferencesEntity> { - return await this.upsertPreferencesUsecase.upsertWorkflowPreferences( + private async upsertWorkflowPreferences(workflow: NotificationTemplateEntity, command: UpsertWorkflowCommand) { + await this.upsertPreferencesUsecase.upsertWorkflowPreferences( UpsertWorkflowPreferencesCommand.create({ environmentId: workflow._environmentId, organizationId: workflow._organizationId, diff --git a/libs/application-generic/src/usecases/upsert-preferences/upsert-preferences.usecase.ts b/libs/application-generic/src/usecases/upsert-preferences/upsert-preferences.usecase.ts index 7b9e3d388dd..9f00974a8b9 100644 --- a/libs/application-generic/src/usecases/upsert-preferences/upsert-preferences.usecase.ts +++ b/libs/application-generic/src/usecases/upsert-preferences/upsert-preferences.usecase.ts @@ -110,7 +110,14 @@ export class UpsertPreferences { throw new BadRequestException('Preference not found'); } - return this.deletePreferences(command, foundPreference?._id); + await this.deletePreferences(command, foundPreference?._id); + + /* + * Ideally we need to return the foundPreference with a deleted: true flag + * but the repository does not support this yet. For now we will make a compromise + * to avoid refactoring all the usages of this usecase. + */ + return foundPreference; } if (foundPreference) { @@ -162,7 +169,7 @@ export class UpsertPreferences { private async deletePreferences( command: UpsertPreferencesCommand, preferencesId: string, - ): Promise<PreferencesEntity> { + ) { return await this.preferencesRepository.delete({ _id: preferencesId, _environmentId: command.environmentId,