Skip to content

Conversation

@michaelwschultz
Copy link
Owner

@michaelwschultz michaelwschultz commented Dec 9, 2025

Fixes three bugs: first-time API logging crash, user deletion leaving behind infusions, and missing avatar fallback.

The API logging crashed because postInfusionByApiKey expected an existing infusion record, failing when none was present. The user deletion was not awaited, and the infusion cleanup query used an incorrect field, leading to orphaned data. The avatar fallback was insufficient, often resulting in a blank display.


Open in Cursor Open in Web


Note

Allows logging an infusion with no prior record, ensures user deletion removes related infusions, and adds robust avatar initial fallback.

  • Backend/API:
    • postInfusionByApiKey accepts lastInfusion as null and constructs a default base infusion/user; sanitizes fields and merges medication/user; enforces createdAt/deletedAt.
    • log-treatment passes null when no prior infusion exists.
  • Database:
    • deleteUser now awaits user doc deletion and deletes related infusions via where('user.uid', '==', uid).
  • UI:
    • Header computes avatarInitial from name/displayName/email with ? fallback and uses it for Avatar.text.

Written by Cursor Bugbot for commit 9a7682c. This will update automatically on new commits. Configure here.

@cursor
Copy link

cursor bot commented Dec 9, 2025

Cursor Agent can help with this pull request. Just @cursor in comments and I'll start working on changes in this branch.
Learn more about Cursor Agents

@vercel
Copy link

vercel bot commented Dec 9, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Comments Updated (UTC)
hemolog-com Ready Ready Preview Comment Dec 9, 2025 6:43am

if (error) throw error

const mostRecentInfusion = infusions[0]
const mostRecentInfusion = infusions && infusions.length > 0 ? infusions[0] : null
Copy link

Choose a reason for hiding this comment

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

Bug: Sparse array causes incorrect null check for infusions

The check infusions.length > 0 doesn't correctly detect when there are no infusions. The upstream getRecentUserInfusionsByApiKey function sets infusions.length = 3 unconditionally, creating a sparse array even when no infusions exist. This means infusions.length > 0 is always true, and infusions[0] returns undefined (not null) when the user has no infusions. The parameter type expects TreatmentType | null, but undefined gets passed instead, which could cause type errors in strict mode and doesn't match the intended behavior.

Fix in Cursor Fix in Web

...baseInfusion,
createdAt: now,
cause: baseInfusion.cause || '',
sites: baseInfusion.sites || '',
Copy link

Choose a reason for hiding this comment

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

Bug: New treatments inherit cause and sites from previous treatment

The refactored code preserves cause and sites values from lastInfusion when they're non-empty, whereas the original code always reset them to empty strings. When a user logs a new treatment via API, the cause and sites fields from their previous treatment will now carry over unless explicitly overridden by newInfusion. Each treatment event has its own cause and injection sites, so inheriting these from a previous treatment produces incorrect data. The baseInfusion.cause || '' pattern keeps existing values, but the old Object.assign with cause: '' always cleared them.

Fix in Cursor Fix in Web

@michaelwschultz michaelwschultz marked this pull request as ready for review December 9, 2025 21:26
@michaelwschultz michaelwschultz changed the title Fix three bugs Allows logging an infusion with no prior record, ensures user deletion removes related infusions, and adds robust avatar initial fallback Dec 20, 2025
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.

3 participants