Allows logging an infusion with no prior record, ensures user deletion removes related infusions, and adds robust avatar initial fallback#81
Conversation
Co-authored-by: michaelwschultz <michaelwschultz@gmail.com>
|
Cursor Agent can help with this pull request. Just |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
| if (error) throw error | ||
|
|
||
| const mostRecentInfusion = infusions[0] | ||
| const mostRecentInfusion = infusions && infusions.length > 0 ? infusions[0] : null |
There was a problem hiding this comment.
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.
| ...baseInfusion, | ||
| createdAt: now, | ||
| cause: baseInfusion.cause || '', | ||
| sites: baseInfusion.sites || '', |
There was a problem hiding this comment.
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.
Fixes three bugs: first-time API logging crash, user deletion leaving behind infusions, and missing avatar fallback.
The API logging crashed because
postInfusionByApiKeyexpected 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.Note
Allows logging an infusion with no prior record, ensures user deletion removes related infusions, and adds robust avatar initial fallback.
postInfusionByApiKeyacceptslastInfusionasnulland constructs a default base infusion/user; sanitizes fields and merges medication/user; enforcescreatedAt/deletedAt.log-treatmentpassesnullwhen no prior infusion exists.deleteUsernow awaits user doc deletion and deletes related infusions viawhere('user.uid', '==', uid).HeadercomputesavatarInitialfromname/displayName/emailwith?fallback and uses it forAvatar.text.Written by Cursor Bugbot for commit 9a7682c. This will update automatically on new commits. Configure here.