Juhitha create injury trend chart#1723
Conversation
aditya2512
left a comment
There was a problem hiding this comment.
This PR provides a strong and well-architected backend solution for supporting the Injury Trend chart feature. The new endpoints efficiently aggregate injury data by month and severity, returning results in a frontend-ready format that will streamline data visualization and analytics. The validation logic on fields like projectId, date, and severity is rigorous, promoting data integrity in both POST and GET operations. I appreciate that error messages are clear, and the design allows both single and bulk injury creation via a flexible API payload. Before merging, please resolve the outstanding branch conflicts and consider providing brief API endpoint documentation for frontend and QA reference. Overall, this is a well-tested and maintainable addition that will meaningfully improve the project’s reporting capabilities.
|
Tested locally and fixed merge conflicts. Uploading Screen Recording 2026-03-02 at 10.32.27 PM.mov… |
|






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…