add task solution#940
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your implementation successfully meets all stated requirements. The expense tracking app correctly implements two collections (users and expenses) with five endpoints each, uses Express.js as specified, maintains in-memory storage that persists during runtime, and returns appropriate HTTP status codes (404 for missing entities, 400 for missing required parameters). The exported createServer() function returns the Express app without calling app.listen(), which is the expected pattern for testing.
Regarding the file comment about adding userId validation to the PATCH endpoint for consistency - while this would indeed be a good practice, it's not a critical blocker since the task requirements don't explicitly mandate this validation. Your implementation satisfies all explicit requirements, and the code is well-structured.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
|
|
||
| app.patch('/expenses/:id', (req, res) => { | ||
| const id = Number(req.params.id); | ||
| const expense = expenses.find((e) => e.id === id); | ||
|
|
||
| if (!expense) { | ||
| return res.status(404).send('Not found'); | ||
| } | ||
|
|
||
| const { userId, spentAt, title, amount, category, note } = req.body || {}; | ||
|
|
||
| if (userId !== undefined) { | ||
| expense.userId = userId; |
There was a problem hiding this comment.
The PATCH /expenses/:id endpoint allows updating userId to a non-existent user without validation. While the task requirements don't explicitly mandate this, the POST /expenses endpoint validates userId exists - consider adding the same validation here for consistency when userId is being updated.
No description provided.