0:00 All right. So in this lecture, we now want to actually respond to our 0:04 payment completed event inside of the order domain. 0:08 Now, remember, inside of our payment entity, when we are 0:12 executing our complete method, we are emitting the payment 0:15 completed event. Now, at this point, once a payment is complete 0:19 in our system, this is when we actually want to now 0:23 transition the underlying order that this payment is 0:27 correlated with and transition that order's state to 0:30 confirmed. Once an order is in a confirmed state, as we know, 0:34 we send our email to our shipping department, and we send that order off for 0:38 shipment. That makes the most sense in our 0:40 application. 0:42 But here's the question: How do we actually listen and respond to 0:45 this payment completed event, which is happening inside of the 0:49 payment domain, inside of the order domain? 0:52 Of course, we could just set up any old event 0:54 listener in the order domain and 0:56 listen for events in other domains. However, this isn't very clean. 1:00 We want our domains to only be listening to 1:04 events that are emitted from the same domain. 1:07 Now, in order to actually get over this 1:08 problem, NestJS and 1:10 CQRS has a very elegant solution called sagas. 1:15 Sagas are essentially, you can think of, like, sort of interceptors 1:19 that allow us to listen for any sort of event types, and 1:22 then we can then, from that event type, re-emit any new 1:27 event that we want. 1:29 So let's go ahead and see how this works in action. 1:32 Inside of the order domain in application, 1:35 let's go ahead and create a new sagas directory. 1:39 Now, inside of sagas, let's create the new order 1:44 fulfillment 1:45 saga. 1:47 And so here, this is gonna be just like any other 1:50 injectable class inside of NestJS. 1:54 And so we'll export class order
The rest of the transcript is for members.
Sign in