flash-oss / medici

Double-entry accounting system for nodejs + mongoose
MIT License
307 stars 84 forks source link

Feature/multi book commit #113

Open ChyzhykTech opened 9 months ago

ChyzhykTech commented 9 months ago

This PR introduces a new helper function commit designed to handle the transactional commit of multiple entries within a MongoDB session. Using the mongoTransaction helper, ensures atomicity and data integrity during the commit process.

Expected syntax to use:

var entry1 = book1.debit().credit();
var entry2 = book2.debit().credit();
const [j1, j2] = await medici.commit(entry1, entry2);
ChyzhykTech commented 9 months ago

Could you please provide your expert opinion, @koresar, regarding the new function and share your thoughts?

I want to note that the new function requires the creation of corresponding unit tests. However, before proceeding, I would still like to receive feedback regarding the changes.

koresar commented 9 months ago

I would avoid involving sessions for the single collection document insertions.

ChyzhykTech commented 9 months ago

I would avoid involving sessions for the single collection document insertions.

Dear @koresar, Following your suggestion, we won't use a session for a single commit. Additionally, I've implemented a check to disallow committing zero entries (MediciError is thrown).

Could you please review it again?

Thank you.

koresar commented 9 months ago

We need to talk. :)