.
This commit is contained in:
parent
53eb33376c
commit
bc554c180e
@ -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<typeof LandPhoneSchema>;
|
||||
|
||||
@ -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<typeof MobilePhoneSchema>;
|
||||
|
||||
@ -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<CountryProps> {
|
||||
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<CountryProps> {
|
||||
translateZodValidationError("Country creation failed", valueIsValid.error)
|
||||
);
|
||||
}
|
||||
return Result.ok(new Country({ value }));
|
||||
return Result.ok(new Country({ value: Country.sanitize(valueIsValid.data) }));
|
||||
}
|
||||
|
||||
getProps(): string {
|
||||
|
||||
@ -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<EmailAddressProps> {
|
||||
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 {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user