FactuGES_ERP/packages/rdx-ddd/src/domain-entity.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

44 lines
994 B
TypeScript

import { UniqueID } from "./value-objects";
export abstract class DomainEntity<T extends object> {
private _props: T;
public readonly id: UniqueID;
protected constructor(props: T, id?: UniqueID) {
this.id = id ?? UniqueID.generateNewID();
this._props = props;
}
protected get props(): T {
return this._props;
}
protected set props(value: T) {
this._props = value;
}
protected _flattenProps(props: T): { [s: string]: any } {
return Object.entries(props).reduce((result: any, [key, valueObject]) => {
result[key] = valueObject.value;
return result;
}, {});
}
equals(other?: DomainEntity<T>): boolean {
if (!other) {
return false;
}
return other instanceof DomainEntity && this.id.equals(other.id);
}
toString(): { [s: string]: string } {
const flattenProps = this._flattenProps(this.props);
return {
id: this.id.toString(),
...flattenProps.map((prop: any) => String(prop)),
};
}
}