This implementation is without domain events, instead of events there are nested aggregates.
export class WarehouseEntity implements Attributes {
id: string;
name: string;
orders: OrderEntity[];
report?: ReportEntity; // nested aggregate
constructor(attributes: Attributes) {
this.id = attributes.id;
this.name = attributes.name;
this.orders = attributes.orders;
}
addOrder(order: OrderEntity) {
this.orders.push(order);
}
changeOrderStatusToValid(orderId: string, report: ReportEntity) {
const order = this.orders.find((el) => el.id === orderId);
order.changeStatus(true);
this.report = report;
}
}
If you are interested in the option with domain events, then follow the link
Domain model with a clean architecture with ports and adapters. It takes into account some tactical patterns from DDD.
npm install
# development
$ cp .env.example .env
$ npm run start:dev
# unit tests
$ npm run test
# arch tests
$ npm run test:arch
# test coverage
$ npm run test:cov