FactuGES_ERP/apps/server/src/common/domain/value-objects/value-object.ts
2025-02-20 19:55:24 +01:00

32 lines
733 B
TypeScript

import { shallowEqual } from "shallow-equal-object";
export abstract class ValueObject<T> {
protected readonly props: T;
protected constructor(props: T) {
this.props = Object.freeze(props); // 🔒 Garantiza inmutabilidad
}
abstract getValue(): any;
equals(other: ValueObject<T>): boolean {
if (!(other instanceof ValueObject)) {
return false;
}
if (other.props === undefined || other.props === null) {
return false;
}
return shallowEqual(this.props, other.props);
}
/*isEmpty(): boolean {
return this.props === null || this.props === undefined;
}*/
/*toString(): string {
return this.props !== null && this.props !== undefined ? String(this.props) : "";
}*/
}