Skip to content

feat(family-health): add family member health management with CRUD API and profile UI (Closes #142)#185

Open
SakethSumanBathini wants to merge 2 commits into
vallabhatech:mainfrom
SakethSumanBathini:feat/family-health-management
Open

feat(family-health): add family member health management with CRUD API and profile UI (Closes #142)#185
SakethSumanBathini wants to merge 2 commits into
vallabhatech:mainfrom
SakethSumanBathini:feat/family-health-management

Conversation

@SakethSumanBathini

@SakethSumanBathini SakethSumanBathini commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Pushed cleanly — 16 files, 1008 insertions, 3 new files confirmed. Now open the PR:
Go to: https://github.com/SakethSumanBathini/CareSync/pull/new/feat/family-health-management
Use this PR body:

Title: feat(family-health): add family member health management with CRUD API and profile UI (Closes #142)
Base branch: vallabhatech:main
Body:

Summary

Implements full family member health management — users can add up to 20 family members, record their health profile (relationship, date of birth, gender, blood group, allergies, chronic conditions, notes), and edit or remove them from their profile page.

Closes #142

What was built

New files (3)

File Purpose
server/models/FamilyMember.js Separate Mongoose model (not a User subdoc) — user ref for per-user scoping, name/relationship/dateOfBirth/gender/bloodGroup/allergies/conditions/notes/linkedUserId, compound index {user:1, createdAt:-1}
server/routes/family.js 4 REST endpoints (GET/POST/PUT/DELETE) at /api/family — ownership-checked, field-whitelisted (blocks user/_id injection), ObjectId-guarded, max-20 enforced
src/components/FamilyMembers.jsx MUI v6 card grid rendered in Profile — add/edit dialog, delete confirmation, age chip auto-calculated from DOB, blood group chip, allergies/conditions inline

Modified files (3 backend + 3 frontend)

File Change
server/index.js +1 line: mount /api/family after /api/health-metrics (line 73)
src/i18n.js +"family" to ns array
src/pages/Profile.jsx +import +render <FamilyMembers /> after the profile card
src/i18n/locales/*.json (×10) New family namespace (36 keys) in all 10 languages

API endpoints

All routes require Authorization: Bearer <token> (existing authMiddleware).

Method Endpoint Description
GET /api/family List all family members for the current user
POST /api/family Add a member (name required; max 20 enforced)
PUT /api/family/:id Update fields (ownership verified; field whitelist blocks injection)
DELETE /api/family/:id Remove a member

Frontend features

  • Add / Edit / Delete — dialog-based forms with confirmation on destructive actions
  • Age chip — auto-calculated from date of birth
  • Gender, blood group chips — displayed on each card
  • Allergies and conditions — shown inline on the card when present
  • Max-20 guard — Add button disabled + info banner at limit
  • Loading + error states — spinner on fetch, dismissible alert on errors

PR isolation from open PRs #183 and #184

This PR is fully disjoint from #183 (auth.js — untouched). For #184:

Verification

Check Result
node --check on all 3 backend files
Model: user ref, name required, defaults, enum, compound index
Route: all 4 CRUD load, ownership 403, ObjectId guard, max-20, field whitelist
FamilyMembers.jsx esbuild compile
All 18 MUI v6 components + 5 react-icons valid exports
36 component keys == 36 en.json family keys (no missing/extra)
All 10 locales: identical 192 leaf-keys, no empty values
CI=true npm test → 30/30 pass (incl. i18n key-structure test)
npm run build → Compiled successfully (311 KB)

Checklist

Summary by CodeRabbit

  • New Features
    • Added Family Health Management feature enabling users to create and manage profiles for family members within their account.
    • Family member profiles capture essential health information including name, relationship, date of birth, gender, blood group, allergies, medical conditions, and notes.
    • Automatic age calculation displayed on member cards.
    • Support for up to 20 family members per account.
    • Full multilingual support across 10 languages.

@vercel

vercel Bot commented Jun 20, 2026

Copy link
Copy Markdown

@SakethSumanBathini is attempting to deploy a commit to the vallabhatech's projects Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@SakethSumanBathini, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 40 minutes and 29 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan refill rate.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, the refill rate gradually slows as usage increases. The highest same-day bursts are limited more strictly.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 6c37dfb2-5e57-4349-99c2-776628e18327

📥 Commits

Reviewing files that changed from the base of the PR and between 6b4c1d3 and 4d82ed9.

📒 Files selected for processing (2)
  • server/routes/family.js
  • src/components/FamilyMembers.jsx
📝 Walkthrough

Walkthrough

Adds a complete Family Health Management feature: a FamilyMember Mongoose model with user ownership, authenticated Express CRUD routes mounted at /api/family, a FamilyMembers React component with MUI dialogs and card-based member list, and family translation strings across 10 locales, all integrated into the Profile page.

Changes

Family Health Management

Layer / File(s) Summary
FamilyMember Mongoose model
server/models/FamilyMember.js
Defines FamilyMemberSchema with user ownership reference, profile fields (name, relationship, dateOfBirth, gender enum, bloodGroup, allergies, conditions, notes), optional linkedUserId, a createdAt timestamp, a compound { user, createdAt } index, and exports the model.
Authenticated REST API
server/routes/family.js, server/index.js
Implements pickFields sanitization helper with EDITABLE_FIELDS whitelist, MAX_FAMILY_MEMBERS limit, and four authenticated endpoints (GET /, POST /, PUT /:id, DELETE /:id) with ownership validation and 400/403/404/500 error responses. Mounts the router at /api/family.
FamilyMembers React component
src/components/FamilyMembers.jsx
Fetches members from GET /api/family, renders member cards with age/gender/blood-group chips and conditional allergies/conditions/notes, provides an add/edit MUI dialog with full form fields and saving state, and a delete confirmation dialog.
i18n namespace and translations
src/i18n.js, src/i18n/locales/*.json
Adds "family" to the i18next ns array and provides family translation objects in all 10 locale files (en, ar, de, es, fr, hi, ja, pt, ru, zh) covering titles, form labels, placeholders, state/error messages, and action buttons.
Profile page integration
src/pages/Profile.jsx
Imports FamilyMembers and renders it as an additional section within the existing Profile page layout.

Sequence Diagram(s)

sequenceDiagram
  participant User
  participant FamilyMembers
  participant API as /api/family
  participant MongoDB

  User->>FamilyMembers: opens Profile page
  FamilyMembers->>API: GET /api/family
  API->>MongoDB: find({ user }) sorted by createdAt desc
  MongoDB-->>API: member documents
  API-->>FamilyMembers: JSON array
  FamilyMembers-->>User: renders member cards

  User->>FamilyMembers: clicks Add / Edit
  FamilyMembers-->>User: opens MUI dialog with form
  User->>FamilyMembers: submits form (name required)
  FamilyMembers->>API: POST /api/family or PUT /api/family/:id
  API->>MongoDB: count check then save / findById + ownership + save
  MongoDB-->>API: saved document
  API-->>FamilyMembers: 200 JSON
  FamilyMembers-->>User: closes dialog, refreshes list

  User->>FamilyMembers: clicks Delete
  FamilyMembers-->>User: opens confirmation dialog
  User->>FamilyMembers: confirms
  FamilyMembers->>API: DELETE /api/family/:id
  API->>MongoDB: findById + ownership + findByIdAndDelete
  MongoDB-->>API: deleted
  API-->>FamilyMembers: 200 JSON
  FamilyMembers-->>User: refreshes list
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Suggested labels

ELUSOC, VETERAN

Suggested reviewers

  • vallabhatech

Poem

🐇 A family tree now blooms in CareSync's halls,
With members and allergies logged on the walls.
A mongoose schema, so neatly designed,
Ten languages speak what the rabbit has signed.
Add, edit, delete — the bunnies rejoice,
Each family member now has a voice! 🌿

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 60.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the primary change: adding family member health management with a complete CRUD API and profile UI integration.
Linked Issues check ✅ Passed The PR fully implements family health management (#142) with CRUD operations, permission controls via user scoping, and health data recording across backend API, frontend UI, and i18n support.
Out of Scope Changes check ✅ Passed All changes are directly scoped to family health management: backend models/routes, frontend component, i18n config/locales, and Profile page integration—no unrelated modifications present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/routes/family.js`:
- Around line 32-34: The dateOfBirth field assignment on line 33 accepts any
parseable input and creates a Date object, but does not validate whether the
resulting Date is actually valid. When an invalid date string is passed,
JavaScript creates an Invalid Date object which later fails during Mongoose save
with a 500 error instead of a 400 validation error. Add validation after
creating the Date object from body.dateOfBirth to check if it is a valid date
using isNaN() on the getTime() method, and if invalid, return a 400 status
response with an appropriate error message before the save attempt. Apply this
same validation pattern to the other date field assignments mentioned in lines
58-79 and 97-104.
- Around line 89-95: The code currently performs ownership verification and
mutation as separate database operations, creating a race condition where the
document could change between the check and the update/delete. To fix this,
combine the ownership check directly into the update and delete queries using a
compound query condition that includes both the document ID and the ownership
predicate. This makes the authorization and mutation atomic in a single database
operation. Apply this pattern to all PUT and DELETE handlers that currently use
the findById pattern followed by ownership verification.
- Around line 66-75: The countDocuments check on line 66 and the member.save()
call on line 73 create a race condition where concurrent requests can bypass the
MAX_FAMILY_MEMBERS limit. Make this operation atomic by wrapping both the count
check and the member creation in a database transaction, or alternatively use
MongoDB's atomic operations such as findOneAndUpdate with a condition that
enforces the limit atomically. This ensures that only one request can
successfully create a member when the limit is reached.

In `@src/components/FamilyMembers.jsx`:
- Around line 147-156: The confirmDelete function lacks protection against
duplicate submissions when users click rapidly, which can trigger multiple
DELETE requests and display false errors. Add an in-flight state flag (such as
an isDeleting state variable) that is set to true when the delete request begins
and false when it completes (in both the try and catch blocks). Use this flag to
guard the beginning of the confirmDelete function to prevent execution if a
delete operation is already in progress, and also disable the delete button in
the UI while isDeleting is true to prevent multiple rapid clicks from reaching
the confirmDelete function.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 8ac09ade-a0d0-4ff8-89e7-33ec9e144a8e

📥 Commits

Reviewing files that changed from the base of the PR and between 636917d and 6b4c1d3.

📒 Files selected for processing (16)
  • server/index.js
  • server/models/FamilyMember.js
  • server/routes/family.js
  • src/components/FamilyMembers.jsx
  • src/i18n.js
  • src/i18n/locales/ar.json
  • src/i18n/locales/de.json
  • src/i18n/locales/en.json
  • src/i18n/locales/es.json
  • src/i18n/locales/fr.json
  • src/i18n/locales/hi.json
  • src/i18n/locales/ja.json
  • src/i18n/locales/pt.json
  • src/i18n/locales/ru.json
  • src/i18n/locales/zh.json
  • src/pages/Profile.jsx

Comment thread server/routes/family.js
Comment thread server/routes/family.js
Comment thread server/routes/family.js Outdated
Comment thread src/components/FamilyMembers.jsx
@SakethSumanBathini

Copy link
Copy Markdown
Contributor Author

Hi @vallabhatech — follow-up commit (4d82ed9) addresses the CodeRabbit review: dateOfBirth validation returns 400 on invalid input, PUT/DELETE ownership checks are now atomic (single DB op each), and the delete button has a double-submit guard. One comment (MAX_FAMILY_MEMBERS transaction) is deferred — MongoDB transactions require a replica set and would break the route on the current deployment setup. CI still passes 30/30. Ready for review!

@sonarqubecloud

Copy link
Copy Markdown

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.

Family Health Management

1 participant