Skip to content

Develop#152

Open
robsza1122 wants to merge 5 commits intomate-academy:masterfrom
robsza1122:develop
Open

Develop#152
robsza1122 wants to merge 5 commits intomate-academy:masterfrom
robsza1122:develop

Conversation

@robsza1122
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! 😊 There are a few critical issues that need to be addressed before your code can be approved. Most importantly, the logic for storing expenses in db/expense.json currently overwrites the file with each new submission instead of maintaining a list of all expenses. This means only the latest expense is saved, which does not meet the core requirements of the task. Additionally, there is a minor but important mistake in setting the response header for JSON error responses—you should use res.setHeader('Content-Type', 'application/json'); instead of res.hasHeader(...). Please update your code to always store expenses as an array (even if there is only one), and ensure the response headers are set correctly. Once these issues are fixed, your solution will be much stronger! 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 Outdated
Comment on lines +84 to +85
if (Object.keys(parsedData).length) {
parsedData = [parsedData];
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is a logic issue here: if parsedData is an object and has keys, you convert it to an array with just that object, but then immediately push dataObject, resulting in an array with the original object and the new data. However, this logic will never be reached if parsedData is already an array (see line 90). Consider simplifying this logic to always use an array for storing expenses, as mixing objects and arrays can cause confusion and errors.

Comment thread src/createServer.js Outdated
Comment on lines +88 to +89
} else if (!Object.keys(parsedData).length) {
parsedData = dataObject;
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Here, if parsedData is an object with no keys, you set parsedData = dataObject, which means you will overwrite the data with a single object instead of an array. This is inconsistent with the intended structure for storing multiple expenses. You should always store expenses as an array, even if there is only one.

Comment thread src/createServer.js Outdated
});
} catch (err) {
res.statusCode = 400;
res.hasHeader('Content-Type', 'application/json');
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is a mistake here: res.hasHeader('Content-Type', 'application/json'); does not set the header. You should use res.setHeader('Content-Type', 'application/json'); to properly set the response header for JSON error responses.

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! There is still a critical issue: after adding the new expense to the array, the code overwrites the array with just the latest expense object (parsedData = dataObject;). This means only the most recent expense is saved, and previous ones are lost. Please remove that line and make sure you always store and update an array of expenses in db/expense.json. Once you fix this, your solution will fully meet the requirements. 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 +83 to +89
if (typeof parsedData === 'object') {
if (Array.isArray(parsedData)) {
parsedData.push(dataObject);
}

parsedData = dataObject;
}
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: After checking if parsedData is an array and pushing the new expense, the code immediately overwrites parsedData with dataObject. This discards the array and only saves the latest expense. You should remove the line parsedData = dataObject; and ensure that expenses are always stored as an array, appending new expenses to it.

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: 7]

If the issue is within your control, please address it.
The next review attempt will automatically launch in 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.

Review Summary

Thank you for your submission! 🎉 Your code meets most of the requirements, and you have implemented the core functionality using only Node.js core modules, serving the HTML form and handling requests correctly. However, there is a critical issue that you need to address: currently, your code overwrites the entire expense.json file with only the latest expense, causing all previous expenses to be lost. According to the task description, you must persist all submitted expenses by appending each new expense to the existing array in db/expense.json, not overwriting it.

Please review the comments and make sure to fix this data persistence logic in your next iteration. This is essential for the correct functionality of your application. All other requirements are met, and your code structure is clear and easy to follow.

Motivation:
We're approving this PR to help you move forward with your learning journey. Please take the time to address the critical issue mentioned above in your future work to avoid similar problems. Keep up the good work, and don't hesitate to consult the Node.js documentation on file system operations for more guidance. You're making great progress—just remember to always check that your data persistence logic matches the requirements! 🚀


✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨

Footnotes

  1. Rate AI review example

Comment thread src/createServer.js
Comment on lines +83 to +84
if (typeof parsedData === 'object') {
parsedData = dataObject;
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: Here, you overwrite the entire parsedData array with just the new dataObject. This means only the latest expense is saved and all previous ones are lost. Instead, you should push dataObject to parsedData (which should be an array). This is required by the task description and checklist.

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