Skip to content

add task solution#156

Open
DmutroSheva wants to merge 1 commit intomate-academy:masterfrom
DmutroSheva:develop
Open

add task solution#156
DmutroSheva wants to merge 1 commit intomate-academy:masterfrom
DmutroSheva:develop

Conversation

@DmutroSheva
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! However, there is a critical issue with how expenses are appended to db/expense.json. The current logic does not correctly handle the case where the file already contains an array, which can lead to data loss or an invalid data structure. Please revise your code to first check if the parsed data is an array and append the new expense accordingly. If it's an object, convert it to an array with both the existing and new expense. If it's empty, initialize it as an array with the new expense. Once this is fixed, 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 +75 to +84
if (typeof parsedFileData === 'object') {
if (Object.keys(parsedFileData).length) {
parsedFileData = [parsedFileData];
parsedFileData.push(dataObj);
} else if (!Object.keys(parsedFileData).length) {
parsedFileData = dataObj;
} else if (Array.isArray(parsedFileData)) {
parsedFileData.push(dataObj);
}
}
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 logic for updating 'parsedFileData' is incorrect. If 'parsedFileData' is already an array, the code will not reach the 'Array.isArray(parsedFileData)' branch due to the previous 'if (typeof parsedFileData === 'object')' and its nested conditions. This can lead to incorrect data structure and loss of previous expenses. You should first check if 'parsedFileData' is an array, and if so, push the new expense. If it's an object (and not an array), convert it to an array with the existing object and the new one. If it's empty, initialize it as an array with the new expense. Please revise this logic to ensure expenses are always stored as an array and new entries are appended correctly.

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