From bc554c180e319673b5b3a260e6645f5223af17c2 Mon Sep 17 00:00:00 2001 From: david Date: Mon, 20 Apr 2026 20:56:14 +0200 Subject: [PATCH] . --- modules/core/src/common/dto/land-phone.dto.ts | 6 +++++- .../core/src/common/dto/mobile-phone.dto.ts | 6 +++++- packages/rdx-ddd/src/value-objects/country.ts | 8 +++++++- .../rdx-ddd/src/value-objects/email-address.ts | 18 ++++++++++-------- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/modules/core/src/common/dto/land-phone.dto.ts b/modules/core/src/common/dto/land-phone.dto.ts index a28a7be6..12e09067 100644 --- a/modules/core/src/common/dto/land-phone.dto.ts +++ b/modules/core/src/common/dto/land-phone.dto.ts @@ -1,5 +1,9 @@ import { z } from "zod/v4"; -export const LandPhoneSchema = z.string().regex(/^\d{3}-\d{3}-\d{4}$/); +export const LandPhoneSchema = z + .string() + .min(9) + .max(15) + .regex(/^\+?\d{9,15}$/); export type LandPhoneDTO = z.infer; diff --git a/modules/core/src/common/dto/mobile-phone.dto.ts b/modules/core/src/common/dto/mobile-phone.dto.ts index c64c0c27..d6815571 100644 --- a/modules/core/src/common/dto/mobile-phone.dto.ts +++ b/modules/core/src/common/dto/mobile-phone.dto.ts @@ -1,5 +1,9 @@ import { z } from "zod/v4"; -export const MobilePhoneSchema = z.string().regex(/^\d{3}-\d{3}-\d{4}$/); +export const MobilePhoneSchema = z + .string() + .min(9) + .max(15) + .regex(/^\+?\d{9,15}$/); export type MobilePhoneDTO = z.infer; diff --git a/packages/rdx-ddd/src/value-objects/country.ts b/packages/rdx-ddd/src/value-objects/country.ts index d6eb59c6..c2488975 100644 --- a/packages/rdx-ddd/src/value-objects/country.ts +++ b/packages/rdx-ddd/src/value-objects/country.ts @@ -1,6 +1,8 @@ import { Result } from "@repo/rdx-utils"; import { z } from "zod/v4"; + import { translateZodValidationError } from "../helpers"; + import { ValueObject } from "./value-object"; interface CountryProps { @@ -20,6 +22,10 @@ export class Country extends ValueObject { return schema.safeParse(value); } + protected static sanitize(value: string): string { + return value.trim().toUpperCase(); + } + static create(value: string) { const valueIsValid = Country.validate(value); @@ -28,7 +34,7 @@ export class Country extends ValueObject { translateZodValidationError("Country creation failed", valueIsValid.error) ); } - return Result.ok(new Country({ value })); + return Result.ok(new Country({ value: Country.sanitize(valueIsValid.data) })); } getProps(): string { diff --git a/packages/rdx-ddd/src/value-objects/email-address.ts b/packages/rdx-ddd/src/value-objects/email-address.ts index d81e811a..ad5ea9f6 100644 --- a/packages/rdx-ddd/src/value-objects/email-address.ts +++ b/packages/rdx-ddd/src/value-objects/email-address.ts @@ -1,6 +1,8 @@ import { Result } from "@repo/rdx-utils"; import { z } from "zod/v4"; + import { translateZodValidationError } from "../helpers"; + import { ValueObject } from "./value-object"; interface EmailAddressProps { @@ -25,20 +27,20 @@ export class EmailAddress extends ValueObject { return schema.safeParse(value); } - getLocalPart(): string { - return this.props.value.split("@")[0]; + getLocalPart() { + return this.props.value.split("@")[0] ?? ""; } - getDomain(): string { - return this.props.value.split("@")[1]; + getDomain() { + return this.props.value.split("@")[1] ?? ""; } - getDomainExtension(): string { - return this.getDomain().split(".")[1]; + getDomainExtension() { + return this.getDomain()?.split(".")[1] ?? ""; } - getDomainName(): string { - return this.getDomain().split(".")[0]; + getDomainName() { + return this.getDomain()?.split(".")[0] ?? ""; } getProps(): string {