Skip to content

feat(tandoor): Fix nutrition import and add language-agnostic property mapping#877

Merged
CodeWithCJ merged 4 commits intomainfrom
dev
Mar 9, 2026
Merged

feat(tandoor): Fix nutrition import and add language-agnostic property mapping#877
CodeWithCJ merged 4 commits intomainfrom
dev

Conversation

@CodeWithCJ
Copy link
Owner

@CodeWithCJ CodeWithCJ commented Mar 9, 2026

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.

Description

This PR fixes an issue where imported Tandoor recipes often appeared with 0g of nutrients and 0kcal because SparkyFitness was not reading the food_properties field where Tandoor stores auto-calculated data.

Additionally, this change makes the Tandoor integration language-agnostic by leveraging internal slugs and standard API keys, ensuring that localized Tandoor instances (e.g., Spanish "Proteínas") map correctly without needing manual translations in the codebase.

Key Changes

  • Field Support: Now correctly reads from food_properties.
  • Language-Agnostic Mapping: Uses Tandoor's open_data_slug (e.g., property-proteins) for reliable internal matching across all languages.
  • Priority Extraction: Established a clear priority order to ensure data is found regardless of Tandoor configuration:
    1. Structured nutrition object/array.
    2. Auto-calculated food_properties.
    3. Generic properties.
  • Testing: Added SparkyFitnessServer/tests/tandoorService.test.js covering multiple data shapes and localized examples.

Verification Results

Passed 7 unit tests covering all new mapping scenarios, including the localized Spanish data structure provided by the user.

Related Issue

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

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 addresses a critical issue where nutrition data from Tandoor recipe imports was often missing or incorrect. The changes introduce a more robust and flexible mechanism for extracting nutrient information by prioritizing explicit nutrition objects, leveraging Tandoor's auto-calculated food_properties, and implementing language-agnostic mapping using internal slugs. This ensures that SparkyFitness accurately displays nutritional values for imported Tandoor recipes, regardless of the Tandoor instance's language configuration.

Highlights

  • Enhanced Nutrition Data Extraction: Correctly reads nutrition information from Tandoor's food_properties field, resolving issues where imported recipes showed zero nutrients.
  • Language-Agnostic Property Mapping: Implemented mapping using Tandoor's open_data_slug (e.g., property-proteins) for reliable nutrient identification across different languages, eliminating the need for manual translations.
  • Prioritized Data Sourcing: Established a clear hierarchy for extracting nutrition data: explicit nutrition objects/arrays take precedence, followed by auto-calculated food_properties, and then generic properties.
  • Comprehensive Testing: Added new unit tests to validate the mapping logic across various data structures and localized examples, ensuring robustness.
Changelog
  • SparkyFitnessFrontend/package.json
    • Updated the frontend package version from 0.16.5.0 to 0.16.5.1.
  • SparkyFitnessServer/integrations/tandoor/tandoorService.js
    • Refactored the mapTandoorRecipeToSparkyFood method to include food_properties in nutrition data extraction.
    • Introduced a prioritized approach for fetching nutrition values from nutrition object/array, food_properties, and properties.
    • Enhanced extractFromProperties and getNutritionValue to use open_data_slug for language-agnostic matching of nutrient properties.
    • Expanded the nutrientsMap with additional localized and slug-based candidate names for various nutrients.
  • SparkyFitnessServer/package.json
    • Updated the server package version from 0.16.5.0 to 0.16.5.1.
  • SparkyFitnessServer/tests/tandoorService.test.js
    • Added a new test file containing unit tests for TandoorService.mapTandoorRecipeToSparkyFood.
    • Included tests for mapping from food_properties, nutrition object, nutrition array, priority handling, and open_data_slug matching.
Activity
  • CodeWithCJ created this pull request to fix nutrition import issues and improve language support for Tandoor integration.
  • New unit tests were added to SparkyFitnessServer/tests/tandoorService.test.js to cover the updated mapping logic.
  • The author confirmed that 7 unit tests passed, covering various new mapping scenarios, including localized Spanish data.
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 significantly improves the Tandoor integration by adding support for food_properties and making the nutrient mapping language-agnostic through the use of slugs. While the inclusion of comprehensive unit tests is a great addition, it introduces potential security vulnerabilities. Specifically, the getRecipeDetails method is vulnerable to path traversal due to unvalidated input in URL construction, and both searchRecipes and getRecipeDetails allow sensitive headers to be overridden, leading to insecure header handling in API requests. Additionally, there are areas for improvement regarding the robustness of nutrition parsing and preventing potential crashes from invalid data.

@CodeWithCJ
Copy link
Owner Author

/gemini review

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 significantly improves the Tandoor integration by fixing an issue with nutrition data import and making the property mapping language-agnostic, with more robust logic for extracting nutritional values. However, a potential path traversal vulnerability was identified in the getRecipeDetails function where the id parameter is used to construct a URL without proper sanitization; this should be addressed by encoding the id parameter. Additionally, consider refactoring constant definitions and reducing code repetition to improve maintainability.

@CodeWithCJ CodeWithCJ merged commit 78f20fa into main Mar 9, 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