kyhsa93/nestjs-rest-cqrs-example

Why are you persisting database after send event?

iquirino opened this issue · 1 comments

Hello,

I'm sorry, I am studying about DDD and CQRS.

I have to ask you: Why are you persisting database after send event?

https://github.com/kyhsa93/nestjs-rest-cqrs-example/blob/master/src/account/application/command/handlers/open.account.ts

Will the event get dispatched if the database save fails?

Should we call the "await this.accountRepository.save(account);" before calling the "account.commit();"?

Thank you!

@iquirino Thank you for creating the issue.

I think what you said is a better way.

This is the part I didn't think about and missed.

I only thought of Transaction and did not think of any exceptions due to order.

I think we should apply this to other command handlers as well.

I will make a correction within a few days, or if you want submit a pull request, I will review it as soon as possible.

Thank you.