Skip to content

Solution#144

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

Solution#144
andrii-rykal wants to merge 3 commits intomate-academy:masterfrom
andrii-rykal:develop

Conversation

@andrii-rykal
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

Thank you for your hard work! Before your solution can be approved, there are a few critical issues that need to be addressed to meet the core requirements of the task:

  1. Expense Storage Logic: Currently, each new expense overwrites the entire expense.json file. For an expense tracker, you must append each new expense to an array in the file. Please update your server logic to read the existing array, add the new expense, and write the updated array back to the file.
  2. Error Response Format: Error responses from your server are not valid JSON objects. Clients expect JSON, so please ensure all error responses use a format like { "error": "Your error message here" }.
  3. User-Friendly Error Messages: On the client side, error alerts currently display the entire result object, which isn't user-friendly. Please extract and display a specific error message (e.g., result.error) for clearer feedback.
  4. ESLint Configuration: The plugins property in your .eslintrc.js file is misplaced. It should be inside the main configuration object, not after the rules property.

Once you address these issues, your solution will be much closer to meeting all requirements! Keep up the good work—you're almost there! 🚀 If you need help with any of these points, feel free to ask or check the relevant documentation.


✨ 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 .eslintrc.js Outdated
'no-proto': 0,
},
plugins: ['jest']
plugins: ['jest'],
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The 'plugins' property should be inside the main configuration object, not after the 'rules' property. Please move 'plugins: ['jest']' to be inside the main object, either before or after 'rules', but not after the closing bracket of 'rules'.

Comment thread src/createServer.js Outdated
Comment on lines +41 to +44
fs.writeFileSync(
path.join(__dirname, '..', 'db', 'expense.json'),
JSON.stringify(expense, null, 2),
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The code overwrites the entire 'expense.json' file with a single expense object. For an expense tracker, you should append the new expense to an array of expenses in the file, not overwrite it. Please read the existing expenses, add the new one, and write the updated array back to the file.

Comment thread src/createServer.js Outdated
Comment on lines +35 to +36
'"Missing required fields: date, title, amount are required"',
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The error response for missing fields is not a valid JSON object. It should be something like '{ "error": "Missing required fields: date, title, amount are required" }' to ensure clients can parse it as JSON.

Comment thread src/createServer.js Outdated
res.end(JSON.stringify(expense));
} catch (err) {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end('"Failed to process request"');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The error response for a failed request is not a valid JSON object. It should be '{ "error": "Failed to process request" }' for proper JSON parsing by clients.

Comment thread src/form.html Outdated
if (response.ok) {
alert('Expense saved successfully!');
} else {
alert(`Error: ${result}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Minor issue: The error alert displays the entire 'result' object, which may not be user-friendly. Consider displaying a specific error message, such as 'result.error', if available, for clearer feedback to the user.

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

Thank you for your hard work! However, there are several critical issues that need to be addressed before your solution can be approved. Most importantly, your server currently overwrites the entire expense.json file with each new expense instead of appending to an array, which breaks the core functionality of expense tracking. Additionally, server error responses are not consistently valid JSON objects, which is required for proper client-side error handling. On the client side, error messages are not user-friendly, as the entire result object is displayed instead of just the specific error message. Please address these issues to meet the core requirements of the task. Once fixed, your solution will be much stronger! 😊 If you need help, check out resources on working with JSON files in Node.js and best practices for API error responses. Keep going—you’re almost there!


✨ 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 +34 to +36
res.end(
'"Missing required fields: date, title, amount are required"',
);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The error response here is not a valid JSON object. You should send a JSON object like { "error": "Missing required fields: date, title, amount are required" } instead of a plain string. This is required for proper client-side error handling.

Comment thread src/createServer.js Outdated

const filePath = path.join(__dirname, '..', 'db', 'expense.json');

fs.writeFileSync(filePath, JSON.stringify(expense, null, 2));
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Critical Issue: This line overwrites the entire expense.json file with only the latest expense. According to the requirements, you must append each new expense to an array in the file. Please update your logic to read the existing array, add the new expense, and write the updated array back to the file.

Comment thread src/createServer.js Outdated
res.end(JSON.stringify(expense));
} catch (err) {
res.writeHead(500, { 'Content-Type': 'application/json' });
res.end('"Failed to process request"');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The error response here is not a valid JSON object. You should send a JSON object like { "error": "Failed to process request" } instead of a plain string.

Comment thread src/form.html Outdated
if (response.ok) {
alert('Expense saved successfully!');
} else {
alert(`Error: ${result}`);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Issue: The error alert displays the entire result object, which may not be user-friendly. You should display a specific error message, such as result.error, to provide clearer feedback to the user.

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! 🎉 Your implementation now fully meets all the core requirements for the expense tracker task. The server correctly appends new expenses to the expense.json file, all error responses are valid JSON objects, and your client-side code displays error messages in a user-friendly way. The HTML form is well-structured and submits data as required. All necessary files are present and correctly implemented.

The only minor issue is the inclusion of .eslintrc.js, which is not required for the core functionality, but it does not affect your solution. In future projects, try to include only the files necessary for the task to keep your repository clean.

Well done on addressing previous feedback and ensuring robust file handling and error management! Keep reviewing the comments for further improvements, and continue learning from each iteration. If you encounter critical issues in future tasks, make sure to address them promptly to avoid functional problems. Keep up the great work and happy coding! 🚀


✨ 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