Skip to content

Implement form-data server#179

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

Implement form-data server#179
S-Khraban wants to merge 3 commits intomate-academy:masterfrom
S-Khraban:develop

Conversation

@S-Khraban
Copy link

No description provided.

Copy link

@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 start on setting up the Node.js server and handling the form submission! However, this requires changes as two core requirements are not yet met.

  1. Data Persistence: Each new expense submission overwrites the db/expense.json file instead of adding to it. To fix this, you should read the file's content, parse it as an array, add the new expense object, and then write the entire array back to the file.
  2. Response Format: After a successful submission, the server must return an HTML page that displays the submitted JSON. Currently, it returns raw JSON (application/json). Please change the Content-Type header to text/html and wrap the JSON output in a basic HTML structure, for example, using a <pre> tag for good formatting.

Addressing these points will get your project aligned with the requirements.


✨ 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

return;
}

fs.writeFileSync(dataPath, JSON.stringify(parsed, null, 2));

Choose a reason for hiding this comment

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

This line overwrites the expense.json file with only the latest submission. To save all expenses, you should first read the existing data from the file, add the new expense to the collection (likely an array), and then write the entire collection back to the file.

Comment on lines 118 to 119
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(parsed));

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 with well formatted JSON'. Currently, you are returning a response with Content-Type: application/json, which is just the raw JSON data. Consider wrapping the JSON output in a basic HTML structure (e.g., using <pre> tags) and setting the Content-Type header to text/html.

Copy link

@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 effort on setting up the server and handling the form submission. However, this submission requires a few changes as two core requirements from the task description are not yet met.

  1. Data Persistence: The db/expense.json file is being overwritten with each new submission instead of having the new expense added to it. To fix this, you'll need to first read the existing content of the file, parse it into a JavaScript array, push the new expense object into that array, and then write the entire updated array back to the file.

  2. Response Format: After a successful submission, the server should respond with an HTML page, not raw JSON. Please change the Content-Type header to text/html and send back an HTML document that displays the submitted data, for example, within a <pre> tag for nice formatting.

Please address these two points to complete the task. You're close!


✨ 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

return;
}

fs.writeFileSync(dataPath, JSON.stringify(parsed, null, 2));

Choose a reason for hiding this comment

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

This line overwrites expense.json with only the new expense, but the requirement is to add to it. You need to first read the file's content, parse it as an array, push the new parsed expense into that array, and then write the entire updated array back to the file. Remember to handle cases where the file might not exist or is empty.

Comment on lines 103 to 104
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(parsed));

Choose a reason for hiding this comment

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

The task requires returning an HTML page after submission, not raw JSON. The Content-Type header should be text/html. The response body should be an HTML document that includes the submitted JSON, preferably inside a <pre> tag for proper formatting.

Copy link

@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

I am approving this submission as an educational override to help you move forward, but the two main issues from the previous review still need to be addressed. You've done a great job setting up the server to handle the form submission!

Here are the key things to fix:

  1. Data Persistence: The expense.json file is being overwritten with each submission. You'll need to read the file first, add the new expense to the existing data, and then write the complete, updated data back to the file.
  2. Response Format: The server is responding with raw JSON. The requirement is to send back a full HTML page that displays the submitted data, making sure to set the Content-Type header to text/html.

You're on the right track, keep up the great effort!


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

Footnotes

  1. Rate AI review example

return;
}

fs.writeFileSync(dataPath, JSON.stringify(expense, null, 2));

Choose a reason for hiding this comment

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

This line overwrites the expense.json file with only the new expense. The requirement is to add the new expense to the existing ones.

You'll need to first read the file's content (e.g., with fs.readFileSync), parse the JSON into an array, push the new expense into that array, and then write the updated array back to the file.

Comment on lines +106 to +107
res.setHeader('Content-Type', 'application/json');
res.end(JSON.stringify(expense));

Choose a reason for hiding this comment

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

The response here is raw JSON. According to the task description, you need to respond with an HTML page.

The Content-Type header should be text/html, and the body should be an HTML document that displays the submitted JSON, for example, inside a <pre> tag for nice formatting.

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