-
Notifications
You must be signed in to change notification settings - Fork 2
bug: fix createLikes notification logic and avoid mutating updateTransactionById edits #129
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: develop
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -581,11 +581,13 @@ export const updateTransactionById = (transactionId: string, edits: Partial<Tran | |
| const sender = getUserById(senderId); | ||
| const receiver = getUserById(receiverId); | ||
|
|
||
| const finalEdits = { ...edits }; | ||
|
|
||
| // if payment, debit sender's balance for payment amount | ||
| if (isRequestTransaction(transaction)) { | ||
| debitPayAppBalance(receiver, transaction); | ||
| creditPayAppBalance(sender, transaction); | ||
| edits.status = TransactionStatus.complete; | ||
| finalEdits.status = TransactionStatus.complete; | ||
|
|
||
| createPaymentNotification( | ||
| transaction.senderId, | ||
|
|
@@ -594,7 +596,7 @@ export const updateTransactionById = (transactionId: string, edits: Partial<Tran | |
| ); | ||
| } | ||
|
|
||
| db.get(TRANSACTION_TABLE).find(transaction).assign(edits).write(); | ||
| db.get(TRANSACTION_TABLE).find(transaction).assign(finalEdits).write(); | ||
| }; | ||
|
|
||
| // Likes | ||
|
|
@@ -624,14 +626,13 @@ export const createLikes = (userId: string, transactionId: string) => { | |
|
|
||
| const like = createLike(userId, transactionId); | ||
|
|
||
| /* istanbul ignore next */ | ||
| if (userId !== senderId || userId !== receiverId) { | ||
| if (userId !== senderId && userId !== receiverId) { | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| createLikeNotification(senderId, transactionId, like.id); | ||
| createLikeNotification(receiverId, transactionId, like.id); | ||
| } else if (userId === senderId) { | ||
| createLikeNotification(senderId, transactionId, like.id); | ||
| } else { | ||
| createLikeNotification(receiverId, transactionId, like.id); | ||
| } else { | ||
| createLikeNotification(senderId, transactionId, like.id); | ||
|
devin-ai-integration[bot] marked this conversation as resolved.
|
||
| } | ||
|
Comment on lines
+629
to
636
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Original createLikes condition was always true, making branches unreachable The old condition Was this helpful? React with 👍 or 👎 to provide feedback.
Comment on lines
+629
to
636
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🚩 Condition fix changes notification behavior for all like/comment actions The old condition The new This is almost certainly the intended fix, but it's worth confirming there are no E2E tests or frontend logic that depend on self-notifications being generated (e.g., notification count assertions in Cypress tests at Was this helpful? React with 👍 or 👎 to provide feedback.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Confirmed intended — this matches the behavior requested in the task. Checked for dependencies:
Comment on lines
+629
to
636
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 📝 Info: Edge case: sender equals receiver is not guarded If a transaction somehow has Was this helpful? React with 👍 or 👎 to provide feedback.
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Agreed — not a regression (same behavior as before for the |
||
| }; | ||
|
|
||
|
|
@@ -671,14 +672,13 @@ export const createComments = (userId: string, transactionId: string, content: s | |
|
|
||
| const comment = createComment(userId, transactionId, content); | ||
|
|
||
| /* istanbul ignore next */ | ||
| if (userId !== senderId || userId !== receiverId) { | ||
| if (userId !== senderId && userId !== receiverId) { | ||
| createCommentNotification(senderId, transactionId, comment.id); | ||
| createCommentNotification(receiverId, transactionId, comment.id); | ||
| } else if (userId === senderId) { | ||
| createCommentNotification(senderId, transactionId, comment.id); | ||
| } else { | ||
| createCommentNotification(receiverId, transactionId, comment.id); | ||
| } else { | ||
| createCommentNotification(senderId, transactionId, comment.id); | ||
| } | ||
| }; | ||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
📝 Info: Shallow copy of edits prevents mutation of caller's object
The change at
backend/database.ts:584createsfinalEdits = { ...edits }so that whenfinalEdits.statusis set toTransactionStatus.completeon line 590, the originaleditsobject passed by the caller is not mutated. This matters becauseupdateTransactionByIdis called frombackend/transaction-routes.ts:179withreq.body, and mutatingreq.bodycould cause subtle issues if it's referenced again later. The fix is correct and well-scoped.Was this helpful? React with 👍 or 👎 to provide feedback.