SaiKrishna add donut chart route and controller for planned cost breakdown#1699
Conversation
aditya2512
left a comment
There was a problem hiding this comment.
The new API endpoint /api/projects/:id/planned-cost-breakdown leverages MongoDB aggregation to accurately sum planned costs by category for each project, which is ideal for powering a frontend donut chart. The aggregation pipeline is both efficient and easily extensible the $match, $group, and $project stages are well-organized and target the most common reporting needs (Plumbing, Electrical, Structural, Mechanical). I appreciate the use of service/controller layering for separation of concerns, and the parameter validation on projectId reduces risk of erroneous queries.
Returning the results as a category keyed flat object is optimal for direct consumption on the frontend, minimizing data transformation.
|
Thank you all, merging! |

Description
Summary Dashboard: Create a Donut Chart showing Planned Cost Breakdown by Type of Expenditure (WIP Sai Krishna)
The chart should display four categories: Plumbing, Electrical, Structural, and Mechanical, each represented by a different color.
The percentage of the total cost for each category should be displayed next to it in hover text.
Include two filters:
A Project filter to view the cost breakdown for a specific project.
Backend Requirements
API Endpoint:
GET /api/projects/:id/planned-cost-breakdown
Data Structure:
{
plumbing: 5500,
electrical: 4800,
structural: 7600,
mechanical: 6300
}
Database Schema:
{
projectId: ObjectId,
category: String, // Plumbing / Electrical / Structural / Mechanical
plannedCost: Number
}
Data Retrieval Logic:
Query by projectId.
Group planned costs by category.
Sum up planned costs per category.
Return structured breakdown.
Related PRS (if any):
To test this backend PR you need to checkout the #4011 frontend PR.
…
Main changes explained:
…
How to test:
npm installand...to run this PR locallyhttp://localhost:4500/api/projects/68747d37c71d9f67ac207eef/planned-cost-breakdown
6.You can setup the data for other project ids and can test. you need to setup the data in this collection " plannedCosts"
Screenshots or videos of changes: