Skip to content

The Solution#935

Open
1umamaster wants to merge 2 commits into
mate-academy:masterfrom
1umamaster:develop
Open

The Solution#935
1umamaster wants to merge 2 commits into
mate-academy:masterfrom
1umamaster:develop

Conversation

@1umamaster
Copy link
Copy Markdown

No description provided.

Copilot AI review requested due to automatic review settings May 14, 2026 12:48
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 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:

  1. 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.

  2. src/services/expensesSvc.js (or the related controller) - When creating an expense with a non-existent userId, 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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

},

getById(req, res) {
const { id } = req.params;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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) {
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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.

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

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