diff --git a/apps/api/src/app/subscribers/dtos/update-subscriber-request.dto.ts b/apps/api/src/app/subscribers/dtos/update-subscriber-request.dto.ts index 451f9eab489..c426881c976 100644 --- a/apps/api/src/app/subscribers/dtos/update-subscriber-request.dto.ts +++ b/apps/api/src/app/subscribers/dtos/update-subscriber-request.dto.ts @@ -1,11 +1,13 @@ import { ApiProperty } from '@nestjs/swagger'; import { IsEmail, IsLocale, IsOptional, IsString } from 'class-validator'; import { SubscriberCustomData } from '@novu/shared'; +import { Transform } from 'class-transformer'; export class UpdateSubscriberRequestDto { @ApiProperty() - @IsEmail() + @Transform((params) => (params.value === '' ? null : params.value)) @IsOptional() + @IsEmail() email?: string; @ApiProperty() diff --git a/packages/application-generic/src/usecases/update-subscriber/update-subscriber.command.ts b/packages/application-generic/src/usecases/update-subscriber/update-subscriber.command.ts index da5bb8554cd..1de18a3dd91 100644 --- a/packages/application-generic/src/usecases/update-subscriber/update-subscriber.command.ts +++ b/packages/application-generic/src/usecases/update-subscriber/update-subscriber.command.ts @@ -1,6 +1,7 @@ import { IsEmail, IsLocale, IsOptional, IsString } from 'class-validator'; import { SubscriberEntity } from '@novu/dal'; import { SubscriberCustomData } from '@novu/shared'; +import { Transform } from 'class-transformer'; import { EnvironmentCommand } from '../../commands/project.command'; @@ -14,6 +15,7 @@ export class UpdateSubscriberCommand extends EnvironmentCommand { @IsOptional() lastName?: string; + @Transform((params) => (params.value === '' ? null : params.value)) @IsOptional() @IsEmail() email?: string; diff --git a/packages/application-generic/src/usecases/update-subscriber/update-subscriber.usecase.ts b/packages/application-generic/src/usecases/update-subscriber/update-subscriber.usecase.ts index 83bf10f64d4..8d5c07dff36 100644 --- a/packages/application-generic/src/usecases/update-subscriber/update-subscriber.usecase.ts +++ b/packages/application-generic/src/usecases/update-subscriber/update-subscriber.usecase.ts @@ -32,9 +32,7 @@ export class UpdateSubscriber { } const updatePayload: Partial = {}; - if (command.email != null) { - updatePayload.email = command.email; - } + updatePayload.email = command.email; if (command.phone != null) { updatePayload.phone = command.phone; @@ -78,7 +76,9 @@ export class UpdateSubscriber { _environmentId: command.environmentId, _id: foundSubscriber._id, }, - { $set: updatePayload } + { + $set: updatePayload, + } ); return { diff --git a/packages/application-generic/src/utils/subscriber.ts b/packages/application-generic/src/utils/subscriber.ts index d5e19de25be..79cf31830fc 100644 --- a/packages/application-generic/src/utils/subscriber.ts +++ b/packages/application-generic/src/utils/subscriber.ts @@ -7,7 +7,8 @@ export function subscriberNeedUpdate( ): boolean { return ( !!( - subscriberPayload?.email && subscriber?.email !== subscriberPayload?.email + subscriber?.email !== undefined && + subscriber?.email !== subscriberPayload?.email ) || !!( subscriberPayload?.firstName &&