Solution#933
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
User IDs are stored as numbers but expense userId is stored as a string, causing type mismatch in filtering and validation. Convert userId to number using unary plus operator: userId: +req.body.userId.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| filteredExpenses = filteredExpenses.filter( | ||
| (exp) => exp.userId === targetUserId, |
There was a problem hiding this comment.
exp.userId is a string but targetUserId is a number - this comparison will always fail. The expense's userId should be stored as a number like user.id (which uses Date.now()).
| const userId = +req.body.userId; | ||
| const user = tempUserDatabase.find((usr) => { | ||
| return usr.id === userId; |
There was a problem hiding this comment.
userId from req.body is a string, but user.id is a number (Date.now()). This lookup will never find a match since "1" !== 1. Convert userId to a number before the find.
| id: Date.now(), | ||
| userId: req.body.userId, |
There was a problem hiding this comment.
userId should be stored as a number (consistent with user.id) to fix the type mismatch issues on lines 22 and 104-106.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The implementation is well-structured with all 10 endpoints properly implemented, but a critical type mismatch bug from the previous review remains unfixed. On line 116, the expense userId is stored as a string with userId: req.body.userId, while User IDs are stored as numbers (line 87). This breaks the GET /expenses?userId=X filter because string-to-number comparison always fails ("1" === 1 is false). The fix is simple: change line 116 to userId: +req.body.userId to use the unary plus operator for type conversion. Additionally, the same type mismatch issue exists in the PATCH /expenses/:id endpoint—if userId is patched, it would also be stored as a string, causing the same filtering problem. This is [CHECKLIST ITEM #12] - "Convert expense userId to number" which was not addressed in this revision.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Important
Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.
Tip
If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.
Caution
Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.
Footnotes
| } | ||
|
|
||
| const newExpense = { | ||
| id: +Date.now(), |
There was a problem hiding this comment.
Previous review issue NOT fixed: userId should be converted to number using unary plus operator. Currently userId: req.body.userId stores a string, but User IDs are stored as numbers (line 87). This causes GET /expenses?userId=X filtering to fail since "1" === 1 is always false.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation is approved as an educational override to support your learning progress. Great job fixing the critical type mismatch bug in POST /expenses — all 10 endpoints are now functional with proper error handling. One remaining issue to be aware of: in your PATCH /expenses/:id endpoint, when updating the userId field, the value from req.body.userId remains a string, creating the same type inconsistency you already fixed in POST. Apply the same unary plus conversion (+req.body.userId) inside the allowedUpdates loop to ensure numeric consistency. This is a common JavaScript gotcha when handling form data, and recognizing it will strengthen your skills for future projects. Keep up the solid work!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.