fix(partners): allow empty-string email fields on partial updates
@IsOptional() only skips validation for null/undefined; an empty string still trips @IsEmail(). When the operator UI saves billingInfo with a blank contactEmail, the request 400'd with 'must be an email'. Coerce '' → undefined on every @IsEmail-decorated field via a shared @Transform so blank inputs round-trip cleanly.
This commit is contained in:
@@ -1,4 +1,4 @@
|
|||||||
import { Type } from 'class-transformer'
|
import { Transform, Type } from 'class-transformer'
|
||||||
import {
|
import {
|
||||||
IsEmail,
|
IsEmail,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
@@ -12,17 +12,25 @@ import {
|
|||||||
ValidateNested,
|
ValidateNested,
|
||||||
} from 'class-validator'
|
} 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 {
|
class ContactInfoDto {
|
||||||
@IsOptional() @IsString() @MaxLength(200) primaryName?: string
|
@IsOptional() @IsString() @MaxLength(200) primaryName?: string
|
||||||
@IsOptional() @IsEmail() primaryEmail?: string
|
@EmptyToUndefined @IsOptional() @IsEmail() primaryEmail?: string
|
||||||
@IsOptional() @IsEmail() billingEmail?: string
|
@EmptyToUndefined @IsOptional() @IsEmail() billingEmail?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
class BillingInfoDto {
|
class BillingInfoDto {
|
||||||
@IsOptional() @IsString() @MaxLength(200) companyName?: string
|
@IsOptional() @IsString() @MaxLength(200) companyName?: string
|
||||||
@IsOptional() @IsString() @MaxLength(40) vatId?: string
|
@IsOptional() @IsString() @MaxLength(40) vatId?: string
|
||||||
@IsOptional() @IsString() @MaxLength(2) country?: string
|
@IsOptional() @IsString() @MaxLength(2) country?: string
|
||||||
@IsOptional() @IsEmail() contactEmail?: string
|
@EmptyToUndefined @IsOptional() @IsEmail() contactEmail?: string
|
||||||
}
|
}
|
||||||
|
|
||||||
export class UpdatePartnerDto {
|
export class UpdatePartnerDto {
|
||||||
|
|||||||
Reference in New Issue
Block a user