Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Update Subscribers API allowing null #3169

Merged
merged 4 commits into from
Jun 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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