Skip to content

Commit

Permalink
Merge pull request #3169 from jayavardhan3112/next
Browse files Browse the repository at this point in the history
fix:  Update Subscribers API allowing null
  • Loading branch information
Pablo Fernández authored Jun 16, 2023
2 parents c78b8d1 + 6668344 commit a17b1e6
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -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()
Expand Down
Original file line number Diff line number Diff line change
@@ -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';

Expand All @@ -14,6 +15,7 @@ export class UpdateSubscriberCommand extends EnvironmentCommand {
@IsOptional()
lastName?: string;

@Transform((params) => (params.value === '' ? null : params.value))
@IsOptional()
@IsEmail()
email?: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ export class UpdateSubscriber {
}

const updatePayload: Partial<SubscriberEntity> = {};
if (command.email != null) {
updatePayload.email = command.email;
}
updatePayload.email = command.email;

if (command.phone != null) {
updatePayload.phone = command.phone;
Expand Down Expand Up @@ -78,7 +76,9 @@ export class UpdateSubscriber {
_environmentId: command.environmentId,
_id: foundSubscriber._id,
},
{ $set: updatePayload }
{
$set: updatePayload,
}
);

return {
Expand Down
3 changes: 2 additions & 1 deletion packages/application-generic/src/utils/subscriber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ export function subscriberNeedUpdate(
): boolean {
return (
!!(
subscriberPayload?.email && subscriber?.email !== subscriberPayload?.email
subscriber?.email !== undefined &&
subscriber?.email !== subscriberPayload?.email
) ||
!!(
subscriberPayload?.firstName &&
Expand Down

0 comments on commit a17b1e6

Please sign in to comment.