49 lines
1.3 KiB
TypeScript
49 lines
1.3 KiB
TypeScript
import { DomainValidationError, ValueObject } from "@repo/rdx-ddd";
|
|
import { Result } from "@repo/rdx-utils";
|
|
import { z } from "zod/v4";
|
|
|
|
type InvoiceSeriesPaddingLengthProps = {
|
|
value: number;
|
|
};
|
|
|
|
export class InvoiceSeriesPaddingLength extends ValueObject<InvoiceSeriesPaddingLengthProps> {
|
|
private static readonly FIELD = "paddingLength";
|
|
private static readonly ERROR_CODE = "INVALID_INVOICE_SERIES_PADDING_LENGTH";
|
|
|
|
private static validate(value: number) {
|
|
return z
|
|
.number()
|
|
.int()
|
|
.gte(1, { message: "Invoice series padding length must be greater than or equal to 1" })
|
|
.safeParse(value);
|
|
}
|
|
|
|
public static create(value: number) {
|
|
const validationResult = InvoiceSeriesPaddingLength.validate(value);
|
|
|
|
if (!validationResult.success) {
|
|
return Result.fail(
|
|
new DomainValidationError(
|
|
InvoiceSeriesPaddingLength.ERROR_CODE,
|
|
InvoiceSeriesPaddingLength.FIELD,
|
|
validationResult.error.message
|
|
)
|
|
);
|
|
}
|
|
|
|
return Result.ok(new InvoiceSeriesPaddingLength({ value: validationResult.data }));
|
|
}
|
|
|
|
public get value(): number {
|
|
return this.props.value;
|
|
}
|
|
|
|
public toPrimitive() {
|
|
return this.props.value;
|
|
}
|
|
|
|
getProps(): InvoiceSeriesPaddingLengthProps {
|
|
return this.props;
|
|
}
|
|
}
|