fix(foodEntryService): forward meal_type_id to repository in createFoodEntryMeal#746
Conversation
…odEntryMeal The route correctly destructures meal_type_id from req.body and passes it in mealData, but the service dropped it when calling the repository. This caused the repository to fall back to a fragile string-based lookup, resulting in 500 errors when meal type names did not match exactly. Fix: add meal_type_id: mealData.meal_type_id to the object passed to foodEntryMealRepository.createFoodEntryMeal(), so the repository can use the direct UUID lookup path when the ID is available.
Summary of ChangesHello @marcelosj3, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request addresses a critical bug in the Highlights
Changelog
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request correctly forwards the meal_type_id from the service layer to the repository in createFoodEntryMeal. This is a good fix that avoids a potentially failing database lookup by meal type name when the ID is already available. The implementation is clean and correct.
While reviewing, I noticed that foodEntryMealRoutes.js also handles meal_type_id for the update operation. It might be worth verifying if foodEntryService.updateFoodEntryMeal correctly forwards this ID to the repository as well, to prevent a similar issue in the update logic.
Summary
createFoodEntryMealinfoodEntryService.jsreceivesmeal_type_idinmealData(correctly passed from the route), but drops it when constructing the object sent tofoodEntryMealRepository.createFoodEntryMeal().This forces the repository to always use the string-based fallback lookup:
…which causes
500errors when the meal type name doesn't match exactly (e.g. casing differences, custom meal type names).Root Cause
foodEntryMealRoutes.jscorrectly destructures and forwardsmeal_type_id:foodEntryService.jsreceives it inmealDatabut drops it before calling the repository:foodEntryMealRepository.jsalready handlesmeal_type_idcorrectly — it just never receives it:Fix
Add
meal_type_id: mealData.meal_type_id || nullto the object passed to the repository:When
meal_type_idis provided, the repository uses the direct UUID path. When it's absent, the existing string-based fallback still works as before — no behaviour change for existing callers.Testing
meal_type_idUUID → should resolve correctly without string lookupmeal_typestring → existing fallback still works