Learning DDD with example building an invoice #149
Replies: 2 comments 19 replies
-
There is no way to create an example that will match everyone's needs, every case is unique and good architecture depends on a lot of factors.
This description is not very detailed. You want to execute something that relies on multiple entities, or aggregate data from multiple modules? If so, a pattern that can help is Domain Service. I'd just create a service that gets all the data it needs from other modules, then generates whatever you need. Something like: class InvoiceLineItemsGenerationService {
async generateInvoiceLineItems() {
const quote = getQuote(); // <- get the quote, depending on your implementation. can be a simple query call or a method call
const invoice = getInvoice();
const lineItems = generateLineItems(quote, invoice);
return lineItems;
}
} Just expose methods/queries in Quote and in Invoice to get whatever you need. If something is not clear, please provide more details so I can give you a better suggestion. |
Beta Was this translation helpful? Give feedback.
-
Going back to my scenario where I have a query "getPrebookingInvoice". Is the following correct: dto gets passed in controller. Controller sends query to query handler application service. Application service query handler creates a prebooking invoice entity and populates everything using prebooking Invoice entity methods. Now we have an entity in a application or domain service and we want to send that back to the controller to return to the client. Inside the application service do we simply use the prebooking invoice mapper .toResponse method to convert it to a response dto and send the dto to the controller? I saw in your example your find users query handler is returning a user model which comes directly from you database query. Question: Thanks |
Beta Was this translation helpful? Give feedback.
-
I am really dedicated to doing things right from the start and could really use some guidance. I Learning nest js while building a hotel PMS. Currently in my Nest JS project I split my modules up already into things like bookings, invoices, invoice night stay items, invoice fees, invoice discounts, etc. I am wondering if someone could give me a very simple example of how you guys want me to do the following.
I have a quote and an invoice. They share most of the business logic in generating all of the line items, discounts, fees, calculations. I really really love the guide and there is so much for me to learn there but the example is a bit too simple to learn from. Any way someone could give me a very simplified example of how I could have a quote and invoice share generating invoice line items following all of the principles in this repo?
Also if allowed... I am willing to pay someone to be my mentor while I learn. I am a software engineer that is trying to learn building reliable and scalable architecture on my free time because my works simply doesnt care.
Beta Was this translation helpful? Give feedback.
All reactions