Skip to content

Commit

Permalink
refactor(api, application-generic, web, shared, dal): Remove `readOnl…
Browse files Browse the repository at this point in the history
…y` from Preferences `channels` (#6575)
  • Loading branch information
rifont authored Sep 25, 2024
1 parent a2d5301 commit 76b73f2
Show file tree
Hide file tree
Showing 33 changed files with 936 additions and 518 deletions.
15 changes: 7 additions & 8 deletions apps/api/src/app/events/e2e/bridge-sync.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -324,14 +324,13 @@ describe('Bridge Sync - /bridge/sync (POST)', async () => {
},
{
preferences: {
workflow: {
all: {
enabled: false,
readOnly: true,
},
channels: {
inApp: {
enabled: true,
readOnly: true,
},
},
},
Expand All @@ -344,13 +343,13 @@ describe('Bridge Sync - /bridge/sync (POST)', async () => {
});

const dashboardPreferences = {
workflow: { enabled: false, readOnly: true },
all: { enabled: false, readOnly: true },
channels: {
email: { enabled: true, readOnly: false },
sms: { enabled: true, readOnly: false },
inApp: { enabled: false, readOnly: true },
chat: { enabled: true, readOnly: false },
push: { enabled: true, readOnly: false },
email: { enabled: true },
sms: { enabled: true },
inApp: { enabled: false },
chat: { enabled: true },
push: { enabled: true },
},
};

Expand Down
4 changes: 2 additions & 2 deletions apps/api/src/app/events/e2e/bridge-trigger.e2e.ts
Original file line number Diff line number Diff line change
Expand Up @@ -852,7 +852,7 @@ contexts.forEach((context: Context) => {
},
{
preferences: {
workflow: {
all: {
enabled: false,
},
channels: {
Expand Down Expand Up @@ -893,7 +893,7 @@ contexts.forEach((context: Context) => {
},
{
preferences: {
workflow: {
all: {
enabled: false,
},
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ export class UpdatePreferences {
templateId?: string;
}) {
const preferences: WorkflowPreferencesPartial = {
workflow: {
all: {
enabled: PREFERENCE_DEFAULT_VALUE,
readOnly: false,
},
Expand Down
31 changes: 18 additions & 13 deletions apps/api/src/app/preferences/dtos/preferences.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,40 +2,45 @@ import { ChannelTypeEnum } from '@novu/shared';
import { Type } from 'class-transformer';
import { IsBoolean, ValidateNested } from 'class-validator';

export class Preference {
export class WorkflowPreference {
@IsBoolean()
enabled: boolean;

@IsBoolean()
readOnly: boolean;
}

export class ChannelPreference {
@IsBoolean()
enabled: boolean;
}

export class Channels {
@ValidateNested({ each: true })
@Type(() => Preference)
[ChannelTypeEnum.IN_APP]: Preference;
@Type(() => ChannelPreference)
[ChannelTypeEnum.IN_APP]: ChannelPreference;

@ValidateNested({ each: true })
@Type(() => Preference)
[ChannelTypeEnum.EMAIL]: Preference;
@Type(() => ChannelPreference)
[ChannelTypeEnum.EMAIL]: ChannelPreference;

@ValidateNested({ each: true })
@Type(() => Preference)
[ChannelTypeEnum.SMS]: Preference;
@Type(() => ChannelPreference)
[ChannelTypeEnum.SMS]: ChannelPreference;

@ValidateNested({ each: true })
@Type(() => Preference)
[ChannelTypeEnum.CHAT]: Preference;
@Type(() => ChannelPreference)
[ChannelTypeEnum.CHAT]: ChannelPreference;

@ValidateNested({ each: true })
@Type(() => Preference)
[ChannelTypeEnum.PUSH]: Preference;
@Type(() => ChannelPreference)
[ChannelTypeEnum.PUSH]: ChannelPreference;
}

export class PreferencesDto {
@ValidateNested({ each: true })
@Type(() => Preference)
workflow: Preference;
@Type(() => WorkflowPreference)
workflow: WorkflowPreference;

@ValidateNested({ each: true })
@Type(() => Channels)
Expand Down
17 changes: 17 additions & 0 deletions apps/api/src/app/preferences/preferences.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
Body,
ClassSerializerInterceptor,
Controller,
Delete,
Get,
NotFoundException,
Post,
Expand Down Expand Up @@ -63,6 +64,22 @@ export class PreferencesController {
);
}

@Delete('/')
@UseGuards(UserAuthGuard)
async delete(@UserSession() user: UserSessionData, @Query('workflowId') workflowId: string) {
await this.verifyPreferencesApiAvailability(user);

return this.upsertPreferences.upsertUserWorkflowPreferences(
UpsertUserWorkflowPreferencesCommand.create({
environmentId: user.environmentId,
organizationId: user.organizationId,
userId: user._id,
templateId: workflowId,
preferences: null,
})
);
}

private async verifyPreferencesApiAvailability(user: UserSessionData) {
const isEnabled = await this.getFeatureFlag.execute(
GetFeatureFlagCommand.create({
Expand Down
Loading

0 comments on commit 76b73f2

Please sign in to comment.