Skip to content

fix(mobile): sync Health Connect/HealthKit hydration to water intake#1663

Merged
CodeWithCJ merged 1 commit into
mainfrom
dev
Jun 28, 2026
Merged

fix(mobile): sync Health Connect/HealthKit hydration to water intake#1663
CodeWithCJ merged 1 commit into
mainfrom
dev

Conversation

@CodeWithCJ

@CodeWithCJ CodeWithCJ commented Jun 28, 2026

Copy link
Copy Markdown
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!
Note: AI-generated descriptions must be manually edited for conciseness. Do not paste raw AI summaries.

Description

What problem does this PR solve?
(Keep it concise. 1–2 sentences.)
Hydration was sent as type 'hydration' in liters, which the server has no case for, so it fell through to the default branch and was stored as a custom measurement named "hydration" instead of water intake.

Map the hydration metric to the server's water-intake sync path:

  • HealthMetrics: type 'hydration' -> 'water', unit 'L' -> 'ml', and add aggregationStrategy 'sum' so multiple same-day drinks are summed into one daily total (upsertWaterData overwrites per (date, source), so unsummed records would otherwise overwrite each other).
  • Android + iOS transformers: convert volume.inLiters to integer ml.

Now routes through case 'water' -> upsertWaterData -> water_intake table, matching how Garmin/Fitbit/Apple Health water already syncs. Containers are untouched (manual-logging only).

How did you implement the solution?
(Brief technical approach.)

Linked Issue: Closes # #1486

How to Test

  1. Check out this branch and run ...
  2. Navigate to...
  3. Verify that...

PR Type

  • Issue (bug fix)
  • New Feature
  • Refactor
  • Documentation

Checklist

All PRs:

  • [MANDATORY - ALL] Integrity & License: I certify this is my own work, free of malicious code, and I agree to the License terms.

New features only:

  • [MANDATORY for new feature] Alignment: I have raised a GitHub issue and it was reviewed/approved by maintainers or it was approved on Discord.

Frontend changes (SparkyFitnessFrontend/):

  • [MANDATORY for Frontend changes] Quality: I have run pnpm run validate and it passes.
  • [MANDATORY for Frontend changes] Translations: I have only updated the English (en) translation file.

Backend changes (SparkyFitnessServer/):

  • [MANDATORY for Backend changes] Code Quality: I have run typecheck, lint, and tests. New files use TypeScript, new endpoints have Zod schemas, and new endpoints include tests.
  • [MANDATORY for Backend changes] Database Security: I have updated rls_policies.sql for any new user-specific tables.

UI changes (components, screens, pages):

  • [MANDATORY for UI changes] Screenshots: I have attached Before/After screenshots below.

Mobile changes (SparkyFitnessMobile/):

  • [MANDATORY for Mobile changes] Tested on device or emulator: I have verified the changes work on iOS or Android.

Screenshots

Click to expand

Before

before

After

after
image
Screenshot_1782607322

Notes for Reviewers

Optional — use this for anything that doesn't fit above: known tradeoffs, areas you'd like specific feedback on, qustions you have or context that helps reviewers.

Hydration was sent as type 'hydration' in liters, which the server has no
case for, so it fell through to the default branch and was stored as a
custom measurement named "hydration" instead of water intake.

Map the hydration metric to the server's water-intake sync path:
- HealthMetrics: type 'hydration' -> 'water', unit 'L' -> 'ml', and add
  aggregationStrategy 'sum' so multiple same-day drinks are summed into one
  daily total (upsertWaterData overwrites per (date, source), so unsummed
  records would otherwise overwrite each other).
- Android + iOS transformers: convert volume.inLiters to integer ml.

Now routes through case 'water' -> upsertWaterData -> water_intake table,
matching how Garmin/Fitbit/Apple Health water already syncs. Containers
are untouched (manual-logging only).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@github-actions github-actions Bot added bug Something isn't working mobile labels Jun 28, 2026
@github-actions

github-actions Bot commented Jun 28, 2026

Copy link
Copy Markdown

PR Validation Results

Change Detection

  • 📱 Mobile changes detected

⚠️ Recommendations (1)

  • Please link a related GitHub issue (Linked Issue: Closes #123).

✅ All required checks passed.

@github-actions github-actions Bot added the enhancement New feature or request label Jun 28, 2026

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

Copy link
Copy Markdown
Contributor

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 updates the hydration tracking functionality to use milliliters (ml) instead of liters (L) and maps the record type to 'water' with a 'sum' aggregation strategy. This includes updating the data transformers for both Health Connect and HealthKit to convert liters to milliliters, as well as updating corresponding tests and adding a new test for daily aggregation. The reviewer suggests adding defensive checks in both data transformers to ensure that the converted milliliter value is positive and non-zero before returning it, preventing invalid or empty records from being sent to the server.

Important

The consumer version of Gemini Code Assist on GitHub is being sunset. Starting June 18, 2026, new organization installations will be blocked, and all code review activity will officially cease on July 17, 2026.
For more details on the timeline and next steps, please review the Help Documentation.

Comment thread SparkyFitnessMobile/src/services/healthkit/dataTransformation.ts
@CodeWithCJ

Copy link
Copy Markdown
Owner Author

@apedley could you review this once.

@apedley

apedley commented Jun 28, 2026

Copy link
Copy Markdown
Contributor

Looks good!

@CodeWithCJ CodeWithCJ merged commit 5aae758 into main Jun 28, 2026
12 of 18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement New feature or request mobile

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants