Refactored foodController and added validation, safe image deletion, … #787
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
…and error handling, clean up code, destructure req.body, and sort food list by creation date
📌 Pull Request Summary
Fixes
1.Added validation for required fields in addFood and removeFood.
2.Used optional chaining for uploaded images to prevent crashes.
3.Checked existence of food items before deletion.
4.Safely deleted associated image files using fs and path.
5.Sorted food items by creation date in getFoodByRestaurant.
6.Cleaned up destructuring and removed redundant code/parentheses.
🛠️ Type of Change
Please select options that are relevant to your pull request
🔗 Related Issue
Closes #786
✅ Checklist
Please confirm the following before submitting:
npm run devor similar to check code stylemainordevbranch📸 Screenshots (if applicable)
🧠 Additional Notes