0:00 All right, so in this lecture, I wanna go ahead and create a new event 0:04 inside of our order entity. So right now, 0:08 after we place a new order, let's say, for example, we wanna dispatch a 0:12 new order placed event so that our system can react to new 0:16 orders in the system, which is a common use case. 0:18 And so in our case, we'll also create an event handler 0:22 that will 0:22 listen for this event and use a notification service. 0:26 And so we can use the notification service to send a confirmation 0:29 email to the user, letting them know that they have successfully placed an 0:33 order. 0:35 So let's go ahead and do exactly that. 0:38 For this, I'm gonna go ahead and create a new order 0:41 placed event. So for this, inside of domain, 0:45 since this is a domain event, the domain model will be using 0:48 and emitting, 0:49 we wanna keep it inside the domain directory. 0:52 And now we'll create the new events directory. 0:55 And so here, we'll create the new 0:57 order placed event. 1:00 So for the order placed event, we're only gonna expose a single property, 1:04 and 1:04 that's gonna be the order ID. If consumers of it need to use it, 1:08 they can fetch it from the database. 1:10 In our case, we're just gonna use it to dispatch an 1:13 email to the user. 1:14 So all we'll need here is the public readonly 1:17 order ID. 1:19 So with the order placed event now available, we can go 1:23 back to the order entity, and let's actually send the 1:27 event off. So before we return the order, 1:31 we want to call on the newly created order entity, 1:34 order.apply. And remember, since we are 1:38 extending the aggregate route from NestJS CQRS, all of our 1:42 entities have this apply method that allow us to send and
The rest of the transcript is for members.
Sign in