Skip to content

Develop#944

Open
redfield-mp wants to merge 11 commits into
mate-academy:masterfrom
redfield-mp:develop
Open

Develop#944
redfield-mp wants to merge 11 commits into
mate-academy:masterfrom
redfield-mp:develop

Conversation

@redfield-mp
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

Your implementation is missing the second required collection — the expenses collection with all 5 endpoints. The user routes are working correctly (13 tests pass), but all 11 expense tests fail with 404 errors because the /expenses routes aren't registered on the Express server. To fix this, you need to add the expenses collection in src/createServer.js with these endpoints: - POST /expenses — create expense (201) - GET /expenses — list all expenses (200) - GET /expenses/:id — get single expense (200) - PATCH /expenses/:id — update expense (200) - DELETE /expenses/:id — delete expense (204). Add an in-memory expenses array alongside your users array, implement the same error handling pattern (400 for missing required fields, 404 for non-existent IDs), and use the same structure you used for the users collection. This completes the 2 collections × 5 endpoints requirement for the expense tracking app.


✨ 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 +10 to +74
const users = [];
let nextId = 1;

app.use(express.json());

app.post('/users', (req, res) => {
const { name } = req.body;

if (!name) {
return res.status(400).json({ error: 'Name is required' });
}

const newUser = {
id: nextId++,
name,
};

users.push(newUser);

return res.status(201).json(newUser);
});

app.get('/users', (req, res) => {
return res.json(users);
});

app.get('/users/:id', (req, res) => {
const { id } = req.params;
const user = users.find((currentUser) => currentUser.id === Number(id));

if (!user) {
return res.status(404).json({ error: 'User not found' });
}

return res.json(user);
});

app.patch('/users/:id', (req, res) => {
const { id } = req.params;
const { name } = req.body;
const user = users.find((u) => u.id === Number(id));

if (!user) {
return res.status(404).json({ error: 'User not found' });
}

if (name) {
user.name = name;
}

return res.json(user);
});

app.delete('/users/:id', (req, res) => {
const { id } = req.params;
const index = users.findIndex((u) => u.id === Number(id));

if (index === -1) {
return res.status(404).json({ error: 'User not found' });
}

users.splice(index, 1);

return res.sendStatus(204);
});
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Only the 'users' collection is implemented. The task requires 2 collections with 5 endpoints each for an expense tracking app. Based on the requirements, you need to add a second collection (likely 'expenses' or 'transactions') with its own 5 endpoints: POST, GET all, GET by ID, PATCH by ID, and DELETE by ID.

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 successfully created both collections with all 10 endpoints, and the 404 error handling works correctly. However, the POST /expenses endpoint is missing critical validation for required fields. According to the Swagger API documentation, spentAt, title, amount, and category are required parameters that should trigger a 400 error when not provided — currently, the endpoint accepts requests without these fields and creates expenses with undefined values. Add validation checks like if (!spentAt) return res.status(400).json({ error: 'spentAt is required' }) for each required field, matching the pattern already implemented for the users endpoints. This is a blocker because the API specification explicitly requires these validations, and tests will expect 400 responses for missing required parameters.


✨ 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 +78 to +98
app.post('/expenses', (req, res) => {
const { userId, spentAt, title, amount, category, note } = req.body;
const user = users.find((u) => u.id === userId);

if (!user) {
return res.status(400).json({ error: 'User not found' });
}

const expense = {
id: nextExpenseId++,
userId,
spentAt,
title,
amount,
category,
note,
};

expenses.push(expense);

return res.status(201).json(expense);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This endpoint validates userId but is missing validation for other required fields (spentAt, title, amount, category). According to the Swagger API documentation, these are required parameters. Consider adding validation: if (!spentAt) { return res.status(400).json({ error: 'spentAt is required' }); } and similar checks for title, amount, and category.

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 expense tracking application is complete and fully functional. All 10 endpoints (5 users, 5 expenses) are properly implemented with correct CRUD operations, in-memory storage, and appropriate error handling. The POST /expenses endpoint now correctly validates spentAt, title, amount, and category fields, returning 400 for missing required parameters. Great work implementing 404 handling for non-existent entities and ensuring the server exports correctly without calling app.listen(). Your solution meets all requirements and is ready to use.


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

3 participants