import { UniqueID } from "./value-objects"; export abstract class DomainEntity { protected readonly props: T; public readonly id: UniqueID; protected constructor(props: T, id?: UniqueID) { this.id = id ? id : UniqueID.generateNewID(); this.props = props; } protected _flattenProps(props: T): { [s: string]: any } { return Object.entries(props).reduce((result: any, [key, valueObject]) => { console.log(key, valueObject.value); result[key] = valueObject.value; return result; }, {}); } equals(other: DomainEntity): boolean { 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)), }; } }