Delete Tractor
Delete a tractor from the catalog. This endpoint requires administrator authentication.Soft Delete Implementation - This endpoint performs a soft delete by setting the tractor’s
status to inactive rather than removing it from the database. The tractor record is preserved for data integrity.Endpoint
Authentication
This endpoint requires both authentication and administrator privileges:Path Parameters
Unique identifier of the tractor to delete. Must be a positive integer.
Response Fields
Indicates if the request was successful
The tractor object after deletion (with
status set to inactive)Example Request
Example Responses
Soft Delete Behavior
Status Check
The API first verifies that the tractor exists by querying the database with the provided ID.
Status Update
Instead of deleting the record, the API updates the tractor’s
status field to inactive.Response
The updated tractor object is returned with
status: "inactive", confirming the soft delete.The soft delete approach preserves historical data and maintains referential integrity with other tables (e.g., calculations, recommendations) that may reference this tractor.
Implementation Details
Fromsrc/controllers/tractorController.js:294-319:
Error Responses
400 Bad Request - Invalid ID
400 Bad Request - Invalid ID
Returned when the tractor ID in the URL path is not a valid positive integer.Invalid ID examples:
- Negative numbers:
/api/tractors/-1 - Zero:
/api/tractors/0 - Non-numeric:
/api/tractors/abc - Decimals:
/api/tractors/1.5
401 Unauthorized - Missing Token
401 Unauthorized - Missing Token
401 Unauthorized - Invalid Token
401 Unauthorized - Invalid Token
403 Forbidden - Insufficient Permissions
403 Forbidden - Insufficient Permissions
Returned when the authenticated user is not an administrator (
role_id !== 1).Solution: This endpoint is restricted to administrators only. Regular users cannot delete tractors.404 Not Found
404 Not Found
Returned when no tractor exists with the specified ID.The tractor may have already been deleted or never existed in the database.
500 Internal Server Error
500 Internal Server Error
Returned when an unexpected server error occurs (e.g., database connection issues).
Idempotency
Reactivating Deleted Tractors
Since this is a soft delete, administrators can reactivate a deleted tractor using the Update Tractor endpoint:Cache Invalidation
Deleting (deactivating) a tractor automatically invalidates:
- All tractor list caches (
*tractors*) - All recommendation caches (
*recommendations*)
Impact on Other Endpoints
After deletion (soft delete toinactive):
List Tractors
Inactive tractors are still returned unless filtered by status
Get Available
Inactive tractors are excluded (only shows
status: 'available')Search
Inactive tractors may appear in search results unless filtered
Recommendations
Inactive tractors should be excluded from recommendation logic
Related Endpoints
Get Tractor
View tractor details before deletion
Update Tractor
Reactivate a deleted tractor by changing status
List Tractors
View all tractors including inactive ones
Create Tractor
Add new tractors to replace deleted ones
