Skip to content

Commit

Permalink
fixup! fix(api): Remove subscribers along with their related entities
Browse files Browse the repository at this point in the history
  • Loading branch information
SokratisVidros committed Nov 7, 2024
1 parent f5fcff5 commit 98bf829
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -152,18 +152,15 @@ 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;
} else {
preferences = DEFAULT_WORKFLOW_PREFERENCES;
}

return await this.upsertPreferencesUsecase.upsertUserWorkflowPreferences(
await this.upsertPreferencesUsecase.upsertUserWorkflowPreferences(
UpsertUserWorkflowPreferencesCommand.create({
environmentId: workflow._environmentId,
organizationId: workflow._organizationId,
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 98bf829

Please sign in to comment.