Terrains represent agricultural land parcels with environmental characteristics that affect farming operations. This resource is user-owned, meaning each terrain belongs to a specific authenticated user.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/David9604/BackMaqagr/llms.txt
Use this file to discover all available pages before exploring further.
Overview
The Terrain resource stores information about agricultural land parcels including altitude, slope, soil type, and temperature. Unlike Tractors and Implements, terrains are private to each user and require authentication for all operations.Key Features
- User-owned resources (ownership validation)
- All operations require authentication
- Users can only access their own terrains
- Hard delete implementation (permanent removal)
- Used in recommendation calculations for terrain-specific analysis
Data Model
The Terrain model contains the following fields:Unique identifier for the terrain (auto-generated)
ID of the user who owns this terrain (auto-assigned from JWT token)
Name or identifier for the terrain (e.g., “Parcela Norte”, “Campo Sur”)
Altitude above sea level in meters
Terrain slope as a percentage (0-100)
Type of soil (e.g., “clay”, “sandy”, “loamy”, “silt”)
Average or current temperature in Celsius
Current status of the terrain (e.g., “active”, “inactive”)
Common Operations
List User’s Terrains
Retrieve all terrains owned by the authenticated user with pagination support.Get Terrain by ID
Retrieve a specific terrain by its unique identifier. Only returns the terrain if it belongs to the authenticated user.If the terrain exists but doesn’t belong to the authenticated user, a 404 error is returned to prevent information disclosure.
Create Terrain
Create a new terrain associated with the authenticated user. Theuser_id is automatically assigned from the JWT token.
Update Terrain
Update an existing terrain. Only the owner can update their terrains. Only provided fields are updated (partial update using COALESCE).Delete Terrain
Delete a terrain permanently. Only the owner can delete their terrains.Validation Rules
When creating or updating terrains, the following validation rules apply:Required Fields (Create)
name: Must be a non-empty stringaltitude_meters: Required, must be a numberslope_percentage: Required, must be a number (typically 0-100)soil_type: Required, must be a non-empty string
Optional Fields
temperature_celsius: Number (can be null)status: String (defaults to “active”)
The
user_id field is automatically assigned from the authenticated user’s JWT token and should not be included in the request body.Validation Examples
Ownership Validation
All terrain operations include ownership validation to ensure users can only access their own data:Controller Implementation (src/controllers/terrainController.js)
getTerrainById()- Line 72 in terrainController.jsupdateTerrain()- Line 162 in terrainController.jsdeleteTerrain()- Line 223 in terrainController.js
Error Responses
400 Bad Request
Returned when validation fails or invalid ID format is provided.401 Unauthorized
Returned when authentication token is missing or invalid.404 Not Found
Returned when the terrain does not exist or doesn’t belong to the authenticated user.Use Cases
Agricultural Recommendations
Terrains are used in the recommendation system to calculate optimal tractor-implement pairings based on environmental factors:- Altitude affects engine performance and power requirements
- Slope percentage impacts traction and stability requirements
- Soil type determines implement compatibility
- Temperature can affect operational efficiency
Example: Get recommendations for a terrain
Related Resources
- Authentication - How to obtain JWT tokens for terrain operations
- Recommendations - Use terrains in recommendation calculations
- API Reference - Complete API endpoint documentation
Source Code References
- Model:
src/models/Terrain.js - Controller:
src/controllers/terrainController.js - Routes:
src/routes/terrain.routes.js - Auth Middleware:
src/middleware/auth.middleware.js
