.
This commit is contained in:
parent
53eb33376c
commit
bc554c180e
@ -1,5 +1,9 @@
|
|||||||
import { z } from "zod/v4";
|
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>;
|
export type LandPhoneDTO = z.infer<typeof LandPhoneSchema>;
|
||||||
|
|||||||
@ -1,5 +1,9 @@
|
|||||||
import { z } from "zod/v4";
|
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>;
|
export type MobilePhoneDTO = z.infer<typeof MobilePhoneSchema>;
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { Result } from "@repo/rdx-utils";
|
import { Result } from "@repo/rdx-utils";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
|
|
||||||
import { translateZodValidationError } from "../helpers";
|
import { translateZodValidationError } from "../helpers";
|
||||||
|
|
||||||
import { ValueObject } from "./value-object";
|
import { ValueObject } from "./value-object";
|
||||||
|
|
||||||
interface CountryProps {
|
interface CountryProps {
|
||||||
@ -20,6 +22,10 @@ export class Country extends ValueObject<CountryProps> {
|
|||||||
return schema.safeParse(value);
|
return schema.safeParse(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected static sanitize(value: string): string {
|
||||||
|
return value.trim().toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
static create(value: string) {
|
static create(value: string) {
|
||||||
const valueIsValid = Country.validate(value);
|
const valueIsValid = Country.validate(value);
|
||||||
|
|
||||||
@ -28,7 +34,7 @@ export class Country extends ValueObject<CountryProps> {
|
|||||||
translateZodValidationError("Country creation failed", valueIsValid.error)
|
translateZodValidationError("Country creation failed", valueIsValid.error)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Result.ok(new Country({ value }));
|
return Result.ok(new Country({ value: Country.sanitize(valueIsValid.data) }));
|
||||||
}
|
}
|
||||||
|
|
||||||
getProps(): string {
|
getProps(): string {
|
||||||
|
|||||||
@ -1,6 +1,8 @@
|
|||||||
import { Result } from "@repo/rdx-utils";
|
import { Result } from "@repo/rdx-utils";
|
||||||
import { z } from "zod/v4";
|
import { z } from "zod/v4";
|
||||||
|
|
||||||
import { translateZodValidationError } from "../helpers";
|
import { translateZodValidationError } from "../helpers";
|
||||||
|
|
||||||
import { ValueObject } from "./value-object";
|
import { ValueObject } from "./value-object";
|
||||||
|
|
||||||
interface EmailAddressProps {
|
interface EmailAddressProps {
|
||||||
@ -25,20 +27,20 @@ export class EmailAddress extends ValueObject<EmailAddressProps> {
|
|||||||
return schema.safeParse(value);
|
return schema.safeParse(value);
|
||||||
}
|
}
|
||||||
|
|
||||||
getLocalPart(): string {
|
getLocalPart() {
|
||||||
return this.props.value.split("@")[0];
|
return this.props.value.split("@")[0] ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
getDomain(): string {
|
getDomain() {
|
||||||
return this.props.value.split("@")[1];
|
return this.props.value.split("@")[1] ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
getDomainExtension(): string {
|
getDomainExtension() {
|
||||||
return this.getDomain().split(".")[1];
|
return this.getDomain()?.split(".")[1] ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
getDomainName(): string {
|
getDomainName() {
|
||||||
return this.getDomain().split(".")[0];
|
return this.getDomain()?.split(".")[0] ?? "";
|
||||||
}
|
}
|
||||||
|
|
||||||
getProps(): string {
|
getProps(): string {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user