Skip to content

Isha - feat: add rental cost chart endpoints - #2429

Open
Isha2303165 wants to merge 2 commits into
developmentfrom
isha-rental-cost-chart-endpoints
Open

Isha2303165 wants to merge 2 commits into
developmentfrom
isha-rental-cost-chart-endpoints

Conversation

@Isha2303165

@Isha2303165 Isha2303165 commented Oct 24, 2026 •

Copy link
Copy Markdown
Contributor

Task:
Screenshot 2026-10-23 at 10 23 06 PM
Implement backend API support for the BM Dashboard rental cost charts.

The backend should provide aggregated rental cost data that can be consumed by the frontend for two visualizations:

  1. Total Rentals Cost Over Time

    • Create an API that returns total rental cost grouped by date.
    • Support filtering by project and date range.
    • Return the data sorted chronologically.
  2. How Much of Tools Costs Are Due to Rentals?

    • Create an API that returns tool cost breakdown grouped by project.
    • Separate the costs into:
      • owned tools cost
      • rented tools cost
    • Support filtering by multiple projects and date range.
    • Return project-level aggregated values in a format suitable for a stacked bar chart.

The APIs should integrate with the existing BM Dashboard data model and routes and remain compatible with the existing rental chart functionality.

Description

Implements the backend support for the rental cost dashboard charts.

This PR adds API endpoints required to display:

  • Total rental cost over time
  • Tool cost breakdown between owned tools and rented tools

It also adds project and date filtering support and ensures rental data is grouped correctly even when projectId values are stored as either strings or MongoDB ObjectIds.

Implements # (WBS)

Related PRS (if any):

Old: Backend PR #1607,
Old: Frontend PR #3813)
New: FrontEnd [PR 5704]OneCommunityGlobal/HighestGoodNetworkApp#5704

To fully test this backend PR, checkout the related frontend PR #XXX in HighestGoodNetworkApp.

Main changes explained:

  • Updated bmRentalChartController.js to add rental cost aggregation APIs.
  • Added GET /api/bm/rentals/cost-over-time.
  • Added GET /api/bm/tools/cost-breakdown.
  • Added filtering by project and date range.
  • Added aggregation of rental costs by date for the line chart.
  • Added aggregation of owned tool costs and rented tool costs by project for the stacked bar chart.
  • Normalized projectId values during aggregation to avoid duplicate project entries when IDs are stored as different MongoDB types.
  • Preserved the existing /api/bm/rentalChart API response for backward compatibility.
  • Updated bmRentalChartRouter.js with the new routes.
  • Updated route registration order so /tools/cost-breakdown is evaluated before the dynamic /tools/:toolId route.
  • Removed duplicate rental chart router registrations.

How to test:

  1. Checkout this branch:
    isha-rental-cost-chart-endpoints
  2. Run npm install if dependencies are not already installed.
  3. Run:
    npm run build
  4. Start the backend:
    npm start
  5. Checkout and run the related frontend PR #XXX.
  6. Log in as an admin user.
  7. Navigate to the BM Dashboard Rental Cost page.
  8. Verify the rental cost over time API returns data successfully.
  9. Verify the tool cost breakdown API returns project-level owned and rented tool costs.
  10. Change the project filter and verify the returned chart data updates correctly.
  11. Change the date range and verify the returned chart data updates correctly.
  12. Verify projects are not duplicated when their projectId is stored as either a string or ObjectId.

Screenshots or videos of changes:

Screenshot 2026-10-23 at 10 25 32 PM

Note:

The backend currently uses the existing rental chart data model containing rentalCost and totalMaterialCost.

For the stacked chart:

  • Rented tools cost is calculated from rentalCost.
  • Owned tools cost is calculated as totalMaterialCost - rentalCost.

The related frontend PR should be used when testing the complete functionality.

@sonarqubecloud

Copy link
Copy Markdown

@one-community one-community changed the title feat: add rental cost chart endpoints Isha - feat: add rental cost chart endpoints Oct 29, 2026
@one-community one-community added invalid This doesn't seem right High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible and removed invalid This doesn't seem right labels Oct 29, 2026

@rahulrubugunday rahulrubugunday 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.

I have reviewed your PR locally (f79392a, frontend on #5704) and it works as per requirement.

  1. The rental cost and tool cost endpoints return data for both charts, and filtering by project and by start/end date returns matching results (Project 1 rented total equals the sum of its rental cost points).
  2. All 14 tests in bmRentalChartController.test.js pass, covering project and date filters, invalid project IDs, owned vs rented tool costs and the error responses.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants