FactuGES_ERP/packages/rdx-ddd/src/value-objects/province.ts
David d57b71c200 refactor: standardize import statements and formatting across components
- Updated import statements in `textarea.tsx`, `toggle.tsx`, and `tooltip.tsx` for consistency.
- Added missing semicolons and adjusted formatting in `use-mobile.ts` and `use-mobile.tsx`.
- Cleaned up `package.json` and `root.json` files by removing unnecessary line breaks.
- Simplified `turbo.json` by consolidating array formatting for better readability.
2026-09-10 13:26:33 +02:00

48 lines
1.0 KiB
TypeScript

import { Result } from "@repo/rdx-utils";
import { z } from "zod/v4";
import { translateZodValidationError } from "../helpers";
import { ValueObject } from "./value-object";
interface ProvinceProps {
value: string;
}
export class Province extends ValueObject<ProvinceProps> {
private static readonly MAX_LENGTH = 255;
protected static validate(value: string) {
const schema = z
.string()
.trim()
.max(Province.MAX_LENGTH, {
message: `Province must be at most ${Province.MAX_LENGTH} characters long`,
});
return schema.safeParse(value);
}
static create(value: string) {
const valueIsValid = Province.validate(value);
if (!valueIsValid.success) {
return Result.fail(
translateZodValidationError("Province creation failed", valueIsValid.error)
);
}
return Result.ok(new Province({ value }));
}
getProps(): string {
return this.props.value;
}
toPrimitive() {
return this.getProps();
}
toString() {
return String(this.props.value);
}
}