Skip to content

Solution#195

Open
KazymyrYan wants to merge 2 commits intomate-academy:masterfrom
KazymyrYan:develop
Open

Solution#195
KazymyrYan wants to merge 2 commits intomate-academy:masterfrom
KazymyrYan:develop

Conversation

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

Good work on setting up the server and handling the form data. Changes are needed to meet two core requirements. First, the expense.json file is being overwritten on each submission instead of accumulating expenses. You'll need to read the file, add the new record to the existing list, and write the updated list back. Second, the server should return an HTML page displaying the JSON, not a raw JSON response. Please set the Content-Type to text/html and wrap the JSON in a <pre> tag for proper browser display.


✨ 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

// arr.push(record);

fs.writeFileSync(filePath, JSON.stringify(record, 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.

The current implementation overwrites the expense.json file with only the latest record. To meet the requirement of saving the expense data, you should append new expenses to the existing list. This typically involves reading the file, parsing the JSON into an array, adding the new record, and then writing the updated array back to the file.

Also, consider what the initial content of the file should be on line 83. If you plan to store a list of expenses, an empty array [] would be more suitable than an empty object {}.

Comment thread src/createServer.js Outdated
Comment on lines +98 to +99
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify(expenseData));
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 requirement is to return an HTML page containing well-formatted JSON. This implementation sends a raw JSON response with the Content-Type set to application/json. You should change the Content-Type to text/html and wrap the JSON string in HTML tags (e.g., <pre>) to display it correctly on a web page.

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 previous feedback on the server's response! I am requesting a change for one remaining critical issue. Currently, when a new expense is submitted, it overwrites the db/expense.json file instead of adding to it. This means only the last submitted expense is ever stored.

To meet the requirement of accumulating expenses, you'll need to:

  1. Read the current contents of db/expense.json.
  2. Parse the JSON string into a JavaScript array.
  3. Push the new expense object into that array.
  4. Write the entire updated array back to the file.

You're very close to finishing this task. Keep up the great work!


✨ 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
amount: expenseData.amount,
};

fs.writeFileSync(filePath, JSON.stringify(record, 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.

This line overwrites the file with only the new record. According to the requirements, you need to accumulate expenses. The correct logic would be to read the file, parse the JSON array, push the new record into it, and then write the entire updated array back to the file.

Copy link
Copy Markdown

@vadiimvooo vadiimvooo left a comment

Choose a reason for hiding this comment

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

Well done

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