Skip to content

fix for missing custom nutrient when a food item is added to diary#900

Merged
CodeWithCJ merged 2 commits intomainfrom
dev
Mar 13, 2026
Merged

fix for missing custom nutrient when a food item is added to diary#900
CodeWithCJ merged 2 commits intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

Tip

Help us review and merge your PR faster!
Please ensure you have completed the Checklist below.
For Frontend changes, please run pnpm run validate to check for any errors.
PRs that include tests and clear screenshots are highly preferred!

Description

Provide a brief summary of your changes.

Related Issue

PR type [x] Issue [ ] New Feature [ ] Documentation
Linked Issue: #

Checklist

Please check all that apply:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers
  • Tests: I have included automated tests for my changes.
  • [MANDATORY for UI changes] Screenshots: I have attached "Before" vs "After" screenshots below.
  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate (especially for Frontend).
  • Translations: I have only updated the English (en) translation file (if applicable).
  • Architecture: My code follows the existing architecture standards.
  • Database Security: I have updated rls_policies.sql for any new user-specific tables.
  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code(phishing, malware, etc.) and I agree to the License terms.

Screenshots (if applicable)

Before

[Insert screenshot/GIF here]

After

[Insert screenshot/GIF here]

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, 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 resolves an issue where custom nutrients were not consistently appearing across the application, specifically when added to a diary or when setting user goals. The changes ensure that custom nutrient data is properly propagated to relevant database tables upon creation and that the frontend cache is refreshed, leading to a more reliable and consistent user experience.

Highlights

  • Frontend Cache Invalidation: Ensured that the 'preferences/nutrients' cache is invalidated whenever custom nutrients are created, updated, or deleted, guaranteeing that the UI reflects the latest custom nutrient list.
  • Backend Custom Nutrient Propagation: Implemented logic to automatically add newly created custom nutrients to 'goal_presets' and relevant 'user_goals' with a default value of 0, resolving issues where custom nutrients were not appearing in goal settings.
  • Conditional Custom Nutrient Sanitization: Updated the food entry creation process to only sanitize 'custom_nutrients' if the field is present in the input data, preventing potential errors when custom nutrients are not provided.
Changelog
  • SparkyFitnessFrontend/src/hooks/Foods/useCustomNutients.ts
    • Added queryClient.invalidateQueries({ queryKey: ['preferences', 'nutrients'] }); to the onSuccess callback of useCreateCustomNutrientMutation.
    • Added queryClient.invalidateQueries({ queryKey: ['preferences', 'nutrients'] }); to the onSuccess callback of useUpdateCustomNutrientMutation.
    • Added queryClient.invalidateQueries({ queryKey: ['preferences', 'nutrients'] }); to the onSuccess callback of useDeleteCustomNutrientMutation.
  • SparkyFitnessServer/services/customNutrientService.js
    • Modified the createCustomNutrient method to include SQL queries that update goal_presets and user_goals tables, adding the new custom nutrient with a default value of '0'.
    • Updated error logging message for the new auto-add functionality.
  • SparkyFitnessServer/services/foodEntryService.js
    • Refactored createFoodEntry to conditionally apply sanitizeCustomNutrients only if entryData.custom_nutrients is defined.
Activity
  • No human activity has been recorded for this pull request yet.
Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request introduces a fix for custom nutrients not appearing correctly when a food item is added to the diary. The changes are comprehensive, addressing the issue on both the frontend and backend.

On the backend, new custom nutrients are now correctly propagated to goal_presets and user_goals, ensuring they are available for goal tracking. The logic for handling custom_nutrients when creating a food entry has also been made more robust.

On the frontend, query invalidation has been improved in the custom nutrient management hooks to ensure the UI reflects changes to nutrient preferences.

The changes look good and should resolve the issue. I've added a few suggestions to improve consistency in the frontend hooks.

Comment on lines 81 to 87
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: ['preferences', 'nutrients'],
});
return queryClient.invalidateQueries({
queryKey: customNutrientsKeys.all,
});
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

Similar to the other mutations in this file, the onSuccess handler here has an inconsistent return. It's clearer to call both invalidations without returning a value.

    onSuccess: () => {
      queryClient.invalidateQueries({
        queryKey: ['preferences', 'nutrients'],
      });

      queryClient.invalidateQueries({
        queryKey: customNutrientsKeys.all,
      });
    },

@CodeWithCJ CodeWithCJ merged commit a598c86 into main Mar 13, 2026
6 checks passed
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.

1 participant