Skip to content

Solution#933

Open
Farrelzum wants to merge 3 commits into
mate-academy:masterfrom
Farrelzum:master
Open

Solution#933
Farrelzum wants to merge 3 commits into
mate-academy:masterfrom
Farrelzum:master

Conversation

@Farrelzum
Copy link
Copy Markdown

No description provided.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/createServer.js
Comment on lines +22 to +23
filteredExpenses = filteredExpenses.filter(
(exp) => exp.userId === targetUserId,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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()).

Comment thread src/createServer.js
Comment on lines +104 to +106
const userId = +req.body.userId;
const user = tempUserDatabase.find((usr) => {
return usr.id === userId;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Comment thread src/createServer.js Outdated
Comment on lines +116 to +117
id: Date.now(),
userId: req.body.userId,
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

userId should be stored as a number (consistent with user.id) to fix the type mismatch issues on lines 22 and 104-106.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment thread src/createServer.js Outdated
}

const newExpense = {
id: +Date.now(),
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Choose a reason for hiding this comment

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

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! ✨

Footnotes

  1. Rate AI review example

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