The Solution#935
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation is well-structured with proper MVC architecture, but there's a critical requirement violation that must be fixed. According to the task requirements, you must "return 404 with any message if expected entity doesn't exist" for every request. Currently, your code returns 400 instead of 404 in these cases:
-
src/controllers/usersCtrl.js- When a user is not found (GET by id, PATCH, DELETE), returning 400 is incorrect. A non-existent user is a missing entity, not a bad request - this should return 404. -
src/services/expensesSvc.js(or the related controller) - When creating an expense with a non-existentuserId, the code returns 400. The referenced user is an expected entity in this context, so when it doesn't exist, you must return 404, not 400.
To fix this: Change the status code from 400 to 404 wherever you're checking for non-existent entities (users or expenses) that are being queried by ID, updated, deleted, or referenced as part of another operation.
The 400 status should only be used for missing required parameters or invalid input formats, which you appear to be handling correctly elsewhere.
✨ 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
| }, | ||
|
|
||
| getById(req, res) { | ||
| const { id } = req.params; |
There was a problem hiding this comment.
According to the task requirements, when an expected entity doesn't exist, the response should be 404. Here, a non-existent user returns 400, but it should be 404 since 'user not found' is about a missing entity.
| getAll(filters = {}) { | ||
| let result = expenses; | ||
|
|
||
| if (filters.userId) { |
There was a problem hiding this comment.
Per the task requirements ('return 404 with any message if expected entity doesn't exist' for every request), this should return 404 when the referenced user doesn't exist, not 400.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation is approved. All previous review issues have been successfully resolved - the code now correctly returns 404 for non-existent entities (users and expenses) and 400 only for missing required parameters. The implementation properly follows MVC architecture with 10 endpoints (5 per collection), uses in-memory storage that clears on server restart, and meets all task requirements. No critical issues remain. Well done on addressing the feedback and completing the task.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.