Update Implement
Update the details of an existing agricultural implement. This endpoint uses partial updates (COALESCE), meaning you only need to include the fields you want to change.Endpoint
Path Parameters
The unique identifier of the implement to update
Authentication
Include your JWT token in the Authorization header:Request Body
All fields are optional. Only include the fields you want to update.Name of the implementValidation: Cannot be empty if provided
Manufacturer brand nameValidation: Cannot be empty if provided
Required horsepower (HP) to operate the implementValidation: Must be a positive number if provided
Working width in metersValidation: Must be a positive number if provided
Type of implement. Must be one of:
plowharrowseedersprayerharvestercultivatormowertrailerother
Compatible soil type(s)Example: “Loam”, “Clay”, “All”
Working depth in centimetersValidation: Must be a positive number if provided
Implement weight in kilogramsValidation: Must be a positive number if provided
Current status. Must be one of:
availablemaintenanceinactive
Response
Indicates if the update was successful
Success or error message
The updated implement object with all current field values
Examples
Update Power Requirement and Working Depth
Change Status to Maintenance
Update Multiple Fields
Response Example (200 OK)
The response includes the complete implement object with all fields, not just the fields that were updated.
Error Responses
Invalid ID (400)
Validation Error (400)
Unauthorized (401)
Forbidden - Not Admin (403)
Not Found (404)
Internal Server Error (500)
Partial Updates (COALESCE)
This endpoint uses PostgreSQL’sCOALESCE function for partial updates. This means:
- Only send fields you want to change - Other fields remain unchanged
- Empty request body - No changes are made (but still returns 200 OK)
- Null values - Interpreted as “no change”, not as setting the field to null
Example: Update Only Status
If you only want to change the status fromavailable to maintenance:
implement_name, power_requirement_hp, etc.) remain unchanged.
SQL Implementation
The update query (fromsrc/models/Implement.js:62):
COALESCE($1, implement_name) means: “Use $1 if provided, otherwise keep the current value of implement_name”.
Validation Rules
Field Validation
When updating, fields are validated only if provided:- String fields cannot be empty if provided
- Numeric fields must be positive if provided
- Enum fields (
implement_type,status) must be valid values
Implement Type Values
Status Values
Implementation Notes
- Source:
src/routes/implement.routes.js:426- Route definition - Controller:
src/controllers/implementController.js:205-updateImplementfunction - Model:
src/models/Implement.js:49-update(id, implementData)method - Validation: Fields are validated only if provided in request body
- Middleware Chain:
verifyTokenMiddleware- Validates JWT tokenisAdmin- Checks for admin rolevalidateImplement- Validates provided fieldsupdateImplement- Updates the implement
- Cache Invalidation: Invalidates both
*implements*and*recommendations*cache patterns
Common Update Scenarios
Mark as Under Maintenance
Adjust Power Requirements
After field testing, adjust the power requirement:Update Specifications
Update technical specifications after recalibration:Reactivate Inactive Implement
Related Endpoints
List Implements
View all implements
Get Implement
Retrieve implement details before updating
Create Implement
Add a new implement (Admin only)
Delete Implement
Remove an implement (Admin only)
Changes to implements are reflected immediately in power calculations and recommendation queries.
