54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
import { DomainValidationError, ValueObject } from "@repo/rdx-ddd";
|
|
import { Result } from "@repo/rdx-utils";
|
|
|
|
interface CompanyStatusProps {
|
|
value: string;
|
|
}
|
|
|
|
export enum COMPANY_STATUS {
|
|
ACTIVE = "active",
|
|
DISABLED = "disabled",
|
|
}
|
|
|
|
export class CompanyStatus extends ValueObject<CompanyStatusProps> {
|
|
private static readonly ALLOWED_STATUSES = [COMPANY_STATUS.ACTIVE, COMPANY_STATUS.DISABLED] as const;
|
|
|
|
static create(value: string): Result<CompanyStatus, Error> {
|
|
if (!CompanyStatus.ALLOWED_STATUSES.includes(value as (typeof CompanyStatus.ALLOWED_STATUSES)[number])) {
|
|
return Result.fail(
|
|
new DomainValidationError("INVALID_COMPANY_STATUS", "status", `Status value not valid: ${value}`)
|
|
);
|
|
}
|
|
|
|
return Result.ok(new CompanyStatus({ value }));
|
|
}
|
|
|
|
static createActive(): CompanyStatus {
|
|
return new CompanyStatus({ value: COMPANY_STATUS.ACTIVE });
|
|
}
|
|
|
|
static createDisabled(): CompanyStatus {
|
|
return new CompanyStatus({ value: COMPANY_STATUS.DISABLED });
|
|
}
|
|
|
|
isActive(): boolean {
|
|
return this.props.value === COMPANY_STATUS.ACTIVE;
|
|
}
|
|
|
|
isDisabled(): boolean {
|
|
return this.props.value === COMPANY_STATUS.DISABLED;
|
|
}
|
|
|
|
getProps(): string {
|
|
return this.props.value;
|
|
}
|
|
|
|
toPrimitive(): string {
|
|
return this.getProps();
|
|
}
|
|
|
|
toString(): string {
|
|
return String(this.props.value);
|
|
}
|
|
}
|