You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
flowchart TD
A[Order] --> B(new Order)
B --> |event| C(OrderCreatedEvent)
B --> |event| D(OrderPaidEvent)
B --> |persist|G
C --> E
D --> E
F[Database]
E(DomainEvents)
G(Repository)
E --> |persist events|G
G --> |Dispatch events| E
G --> F
Loading
Criar uma Order;
Criar um evento respectivo a sua ação;
Salvar em banco de dados (Repositórios);
Disparar DomainEvents com o id da entidade;
Fluxograma em código
// src/infra/index.ts// SubscriberDomainEvents.registerSubscriber(OrderCreatedEvent.name,(order)=>{console.log("order event",order);});// SubscriberDomainEvents.registerSubscriber(OrderPaidEvent.name,(order)=>{console.log("paid event",order);});// Publisherconstorder=Order.create({customerId: "customer_id",productId: "product_id",amountInCents: 1000,status: "pending",createdAt: newDate(),});order.pay();// Dentro da camada de persistência (repositório)// Finalização do processo de vendaDomainEvents.dispatchEventsForEntity(order.id);