Skip to content

Feat/mongodb transactions#14

Merged
Kmario19 merged 10 commits intomainfrom
feat/mongodb-transactions
Apr 3, 2025
Merged

Feat/mongodb transactions#14
Kmario19 merged 10 commits intomainfrom
feat/mongodb-transactions

Conversation

@Kmario19
Copy link
Owner

@Kmario19 Kmario19 commented Apr 3, 2025

This pull request introduces transaction session management to ensure database consistency during account credit, debit, and transaction creation operations. The changes primarily involve adding session handling to the controllers and updating the corresponding tests to mock session operations.

Transaction session management:

Test updates:

@Kmario19 Kmario19 requested a review from Copilot April 3, 2025 19:57
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 10 out of 10 changed files in this pull request and generated no comments.

Comments suppressed due to low confidence (1)

src/routes/transaction/delete/controller.ts:14

  • The session variable is used without being initialized in this controller. Please add session initialization (e.g., const session = await Transaction.startSession();) and begin the transaction before invoking any session methods.
const transaction = await Transaction.findById(transactionId).session(session);

@Kmario19 Kmario19 requested a review from Copilot April 3, 2025 20:52
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot reviewed 19 out of 20 changed files in this pull request and generated no comments.

Files not reviewed (1)
  • swagger.json: Language not supported
Comments suppressed due to low confidence (3)

src/routes/transaction/edit/controller.ts:23

  • Add a return statement immediately after sending the 'account not found' error response to prevent further execution of the controller logic.
if (!account) { await session.abortTransaction(); res.status(StatusCodes.NOT_FOUND).json({ error: 'Associated account not found' }); }

src/routes/transaction/edit/controller.ts:42

  • Add a return statement after the insufficient funds error response to ensure no further processing is executed after aborting the transaction.
if (account.balance + balanceAdjustment < 0) { await session.abortTransaction(); res.status(StatusCodes.BAD_REQUEST).json({ error: 'Insufficient funds' }); }

src/routes/transaction/create/controller.ts:38

  • When using an array with Transaction.create, Mongoose returns an array of documents; consider extracting the created document or passing a single object to ensure the response aligns with the expected format.
const transaction = await Transaction.create([ { account: accountId, amount, cost, date, type } ], { session });

@Kmario19 Kmario19 merged commit 3795d48 into main Apr 3, 2025
1 check passed
@Kmario19 Kmario19 deleted the feat/mongodb-transactions branch April 3, 2025 20:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants