Skip to content

add task solution#874

Open
nikita4880 wants to merge 3 commits intomate-academy:masterfrom
nikita4880:develop
Open

add task solution#874
nikita4880 wants to merge 3 commits intomate-academy:masterfrom
nikita4880:develop

Conversation

@nikita4880
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

Great work on implementing the API! The code is well-structured and most of the endpoints are working as expected. However, changes are needed for the DELETE endpoints.

Currently, both DELETE /users/:id and DELETE /expenses/:id are missing validation for the id parameter. If a non-numeric ID is provided, the server incorrectly returns a 404 Not Found status instead of the required 400 Bad Request. Please add a validation check to these endpoints to ensure they handle invalid IDs consistently with the GET and PATCH endpoints.


✨ 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
Comment on lines +74 to +75
app.delete('/users/:id', (req, res) => {
const id = Number(req.params.id);
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 is missing validation for the id parameter. If a non-numeric ID is provided, it will incorrectly result in a 404 Not Found instead of a 400 Bad Request. Consider adding a check using isValidId for consistency with the GET and PATCH endpoints for this resource.

Comment thread src/createServer.js Outdated
Comment on lines +217 to +218
app.delete('/expenses/:id', (req, res) => {
const id = Number(req.params.id);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Similar to the DELETE /users/:id endpoint, the id parameter here is not validated. An invalid ID format should result in a 400 Bad Request, but it currently leads to a 404 Not Found. Please add a validation check consistent with the other endpoints that use an 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

Great job addressing the validation for non-numeric IDs in the DELETE endpoints! However, this submission requires changes because the implementation for creating and updating users and expenses does not align with the project requirements.

Here are the specific issues:

  • Users: When creating a user (POST), the required email field is missing. When updating a user (PATCH), email is not handled, and name is incorrectly treated as a required field instead of optional.
  • Expenses: The POST and PATCH endpoints are using incorrect fields (e.g., title, category). The requirements specify that these endpoints should handle userId, description, and amount.

Please carefully review the requirements to ensure the user and expense objects match the specified structure. Aligning the create and update endpoints is the next critical step.


✨ 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
Comment on lines +22 to +36
app.post('/users', (req, res) => {
const { name } = req.body;

if (!name) {
return res.status(400).send('Bad request');
}

const user = {
id: userIdCounter++,
name,
};

users.push(user);

res.status(201).json(user);
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 requirements, a new user should be created with both a name and an email. This implementation is missing the email field when processing the request body and creating the new user object.

Comment thread src/createServer.js Outdated
Comment on lines +55 to +71
app.patch('/users/:id', (req, res) => {
const id = Number(req.params.id);
const { name } = req.body;

if (!isValidId(id) || !name) {
return res.status(400).send('Bad request');
}

const user = users.find((u) => u.id === id);

if (!user) {
return res.status(404).send('Not found');
}

user.name = name;

res.json(user);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The PATCH endpoint for users should allow updating name and/or email optionally. Currently, email is not handled, and name is incorrectly treated as a required field. The update logic should check for the presence of each field individually and update the user object accordingly.

Comment thread src/createServer.js Outdated
Comment on lines +126 to +160
app.post('/expenses', (req, res) => {
const { userId, spentAt, title, amount, category, note } = req.body;

if (
userId === undefined ||
!spentAt ||
!title ||
amount === undefined ||
!category
) {
return res.status(400).send('Bad request');
}

const userExists = users.some((u) => u.id === userId);

if (!userExists) {
return res.status(400).send('Bad request');
}

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

if (note !== undefined) {
expense.note = note;
}

expenses.push(expense);

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.

The fields for creating an expense do not match the task requirements. The required fields are userId, description, and amount. This implementation uses spentAt, title, and category instead, and is missing the required description field.

Comment thread src/createServer.js Outdated
Comment on lines +179 to +218
app.patch('/expenses/:id', (req, res) => {
const id = Number(req.params.id);

if (!isValidId(id)) {
return res.status(400).send('Bad request');
}

const expense = expenses.find((e) => e.id === id);

if (!expense) {
return res.status(404).send('Not found');
}

if (Object.keys(req.body).length === 0) {
return res.status(400).send('Bad request');
}

const { spentAt, title, amount, category, note } = req.body;

if (spentAt !== undefined) {
expense.spentAt = spentAt;
}

if (title !== undefined) {
expense.title = title;
}

if (amount !== undefined) {
expense.amount = amount;
}

if (category !== undefined) {
expense.category = category;
}

if (note !== undefined) {
expense.note = note;
}

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

Similar to the POST endpoint, the fields for updating an expense are incorrect. The requirements state that userId, description, and/or amount should be updatable. This implementation allows updating a different set of fields and does not handle userId or description.

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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

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.

Sorry, the pull request review was unsuccessful for the following reasons:

Warning

No changes were made in the pull request since the last review. Please make sure that you have added files to the pull request and committed the changes.
[CODE: NCM]

If the issue is within your control, please address it.
The next review attempt will automatically launch in about 1 hour.
If you believe this is an error or need assistance, please contact the support team.

Copy link
Copy Markdown

@brespect brespect left a comment

Choose a reason for hiding this comment

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

Good job, but let`s separate your up accourding to MVC model, to routres, services and controllers

Copy link
Copy Markdown

@brespect brespect left a comment

Choose a reason for hiding this comment

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

Perfect 🚀

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