diff --git a/services/platform-api/src/partners/dto/update-partner.dto.ts b/services/platform-api/src/partners/dto/update-partner.dto.ts index 99a9a1c..98fdb91 100644 --- a/services/platform-api/src/partners/dto/update-partner.dto.ts +++ b/services/platform-api/src/partners/dto/update-partner.dto.ts @@ -1,4 +1,4 @@ -import { Type } from 'class-transformer' +import { Transform, Type } from 'class-transformer' import { IsEmail, IsEnum, @@ -12,17 +12,25 @@ import { ValidateNested, } from 'class-validator' +// Coerce '' → undefined so blank form fields don't trip @IsEmail on the +// nested DTOs. @IsOptional() skips validation only for null/undefined, not +// empty strings — without this transform a partial edit fails the moment +// the form contains an unfilled email field. +const EmptyToUndefined = Transform(({ value }: { value: unknown }) => + value === '' ? undefined : value, +) + class ContactInfoDto { @IsOptional() @IsString() @MaxLength(200) primaryName?: string - @IsOptional() @IsEmail() primaryEmail?: string - @IsOptional() @IsEmail() billingEmail?: string + @EmptyToUndefined @IsOptional() @IsEmail() primaryEmail?: string + @EmptyToUndefined @IsOptional() @IsEmail() billingEmail?: string } class BillingInfoDto { @IsOptional() @IsString() @MaxLength(200) companyName?: string @IsOptional() @IsString() @MaxLength(40) vatId?: string @IsOptional() @IsString() @MaxLength(2) country?: string - @IsOptional() @IsEmail() contactEmail?: string + @EmptyToUndefined @IsOptional() @IsEmail() contactEmail?: string } export class UpdatePartnerDto {