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.
![architecture schema](https://private-user-images.githubusercontent.com/44276887/297869254-0b862b4e-6d1e-4882-bb29-1653f296cd56.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzk5NzA1NTMsIm5iZiI6MTczOTk3MDI1MywicGF0aCI6Ii80NDI3Njg4Ny8yOTc4NjkyNTQtMGI4NjJiNGUtNmQxZS00ODgyLWJiMjktMTY1M2YyOTZjZDU2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTklMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjE5VDEzMDQxM1omWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQxNWI3NTBjNDliOTA5MDVhNWQ2MjQwN2RlZmM5NGU3N2Y2OWViNzEwNDM2Y2JlN2YwNzY1Mjg0ODEyZjE3ZDAmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.WSs5jf-92JvX40B2UrxDLhKsX2KNOPOHAQyRp5QpXfE)
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