It's an abstract class that simply provides some standard attributes to your entity through props interface.
* @abstract BaseDomainEntity
* @property ID:DomainId
* @property createdAt:Date
* @property updatedAt:Date
* @property isDeleted:Boolean
* @property deletedAt:Date | undefined
import {
BaseDomainEntity,
Entity,
UniqueEntityID,
Result
} from 'types-ddd';
interface CarProps extends BaseDomainEntity {
year: number;
color: string;
}
class Car extends Entity<CarProps> {
private constructor(props: CarProps, Car.name) {
super (props, id)
}
get year (): number {
return this.props.year;
}
get color (): string {
return this.props.color;
}
public static create (props: CarProps): Result<Car> {
return Result.ok<Car>(new Car(props));
}
}
const car = Car.create({
ID: DomainId.create(),
year: 2021,
color: 'red'
}).getResult();
Accessible attributes for car
> car.color
> car.createdAt
> car.deletedAt
> car.equals
> car.id
> car.isDeleted
> car.updatedAt
> car.year
> car.getHashCode