Juhitha create injury trend chart #1723
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.



Backend PR — Injury Trend APIs + POST injuries
Description
Adds backend support for Injury Trend line chart and provides a production POST endpoint for creating injury records. Trend data returns monthly counts per severity across a date range and project.
Implements #Phase2-InjuryTrend-API
Related PRs (if any):
Main changes explained:
/api/bm/injuries:GET /trend-data: returns{ months, serious, medium, low }aggregated by month and severity, filtered byprojectId,startDate,endDate(inclusive start, month-exclusive end for YYYY-MM-DD).GET /project-injury: lists projects that have injuries (for Project dropdown).GET /injury-severities/GET /injury-types: supporting datasets.POST /(i.e./api/bm/injuries): create injuries (single or bulk).InjuryCategoryschema:projectId: ObjectId (required)projectName: stringdate: Date (required)injuryType: stringworkerCategory: stringseverity: 'Serious' | 'Medium' | 'Low' (required)count: number (default 1, ≥ 0)projectIdmust be a valid ObjectIddatemust parse (YYYY‑MM‑DD or ISO)severitynormalized (case-insensitive) to “Serious | Medium | Low”{ insertedCount, docs }for...ofwith array iterationHow to test:
cd HGNRest && npm installnpm run build && NODE_ENV=development PORT=4500 node dist/server.jshttp://localhost:4500/api/bm/injuriesAuthorization: <JWT>,Content-Type: application/json[ { "projectId": "65419e61105441587e2dec99", "projectName": "Building 1", "date": "2025-02-05", "injuryType": "Fall", "workerCategory": "Electrician", "severity": "Serious", "count": 2 }, { "projectId": "65419e61105441587e2dec99", "projectName": "Building 1", "date": "2025-03-01", "injuryType": "Cut", "workerCategory": "Carpenter", "severity": "Medium", "count": 1 } ]GET http://localhost:4500/api/bm/injuries/trend-data?projectId=65419e61105441587e2dec99&startDate=2025-01-01&endDate=2025-12-31{ months: [...], serious: [...], medium: [...], low: [...] }Screenshots or videos of changes:
Uploading Screen Recording 2025-09-12 at 1.01.13 PM.mov…