Skip to content

Adithya_fix_tool_update_backend#1992

Merged
one-community merged 3 commits intodevelopmentfrom
adithya_fix_tool_update_backend
Apr 9, 2026
Merged

Adithya_fix_tool_update_backend#1992
one-community merged 3 commits intodevelopmentfrom
adithya_fix_tool_update_backend

Conversation

@adithya-6101
Copy link
Copy Markdown
Contributor

@adithya-6101 adithya-6101 commented Jan 7, 2026

Description

Fixes the non-functional "Edit Tool" feature on the BM Dashboard > Tools page. Previously, the backend lacked the necessary logic to process tool updates, causing the frontend modal to fail or display "Under Construction".

image

This PR implements the backend controller logic required to:

  1. Update Tool Details: modifying condition, status, and name.
  2. Handle Status Changes: Atomic logic to safely move tool IDs between "Available" and "Using" arrays without race conditions.
  3. Fix Schema Mismatch: Implemented direct collection access to buildingInventoryTypes to resolve a critical bug where Mongoose updates were returning "0 modified documents" due to a collection naming mismatch.

Related PRS (if any):

This is the Backend PR. To fully test this feature, you must also checkout the corresponding Frontend PR: OneCommunityGlobal/HighestGoodNetworkApp#4681


Main changes explained:

  • bmToolController.js:
    • Implemented updateToolById function.
    • Critical Fix: Used mongoose.connection.collection('buildingInventoryTypes') instead of the default Mongoose model to target the correct database collection.
    • Atomic Updates: Utilized $pull and $addToSet operators to ensure tool IDs are cleanly removed from their old status array and added to the new one in a single operation.
    • Added 404 (Not Found) and 500 (Internal Error) status handling.
  • bmToolRouter.js: - Added the .put() route to connect the frontend request to the new controller method.

How to test:

  1. Checkout the current branch adithya_fix_edit_tool_feature.
  2. Run npm install and npm run dev (or npm start) to start the backend server.
  3. Important: Ensure your IP is whitelisted on MongoDB Atlas if testing locally.
  4. (Frontend Setup): Ensure you are running the frontend branch linked above.
  5. Log in as an Admin or Owner.
  6. Navigate to BM Dashboard -> Tools.
  7. Verify the following scenarios:
    • Status Change: Edit a tool currently marked as "Available" (Red X in Using column). Change status to "Using". Save. Verify the table updates to show a Green Check in the "Using" column.
    • Condition Update: Edit a tool and change condition (e.g., from "Good" to "Worn"). Verify the change reflects in the table.

Screenshots or videos of changes:

Tools.List.-.Google.Chrome.2026-01-22.17-37-55.mp4

Note:

@adithya-6101 adithya-6101 added the Do Not Review Do not review or look at code without full context label Jan 7, 2026
@adithya-6101 adithya-6101 removed the Do Not Review Do not review or look at code without full context label Mar 23, 2026
Copy link
Copy Markdown

@Anusha-Gali Anusha-Gali left a comment

Choose a reason for hiding this comment

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

Hi Adithya,

The API works as per requirement for the PR. The change in data stays after refresh as well.

Image

@beblicarl beblicarl self-requested a review March 26, 2026 12:45
@beblicarl
Copy link
Copy Markdown
Contributor

Tested the backend and everythign worked as intended

OneCommunityGlobal/HighestGoodNetworkApp#4681 (comment)

@one-community one-community added the High Priority - Please Review First This is an important PR we'd like to get merged as soon as possible label Apr 4, 2026
@one-community
Copy link
Copy Markdown
Member

Thank you all, merging!

@one-community one-community merged commit f2d4936 into development Apr 9, 2026
2 checks passed
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.

4 participants