Overview
The API uses Zod for runtime validation of all request data. Zod provides type-safe validation with detailed error messages when data doesn’t match the expected schema.Property Validation Rules
All property data is validated against thePropiedadSchema defined in the source code.
String Fields
codigo_id
- Type: String
- Constraint: Must be exactly 6 characters long
- Required: No (optional, auto-generated if not provided)
- Validation:
z.string().length(6).optional()
pais, ciudad, direccion
- Type: String
- Constraint: No specific length restrictions
- Required: Yes
- Validation:
z.string()
descripcion
- Type: String
- Constraint: No specific length restrictions
- Required: No (optional)
- Validation:
z.string().optional()
Number Fields
ambientes
- Type: Number (integer)
- Constraint: Must be a valid number
- Required: Yes
- Validation:
z.number()
metros_cuadrados
- Type: Number (decimal allowed)
- Constraint: Must be a valid number
- Required: Yes
- Validation:
z.number()
precio
- Type: Number (decimal allowed)
- Constraint: Must be a valid number
- Required: Yes
- Validation:
z.number()
Enum Fields
tipo_contratacion
- Type: Enum
- Allowed values:
"Alquiler"or"Venta"(case-sensitive) - Required: Yes
- Validation:
z.enum(['Alquiler', 'Venta'])
estado
- Type: Enum
- Allowed values:
"Disponible","Reservado","Alquilado", or"Vendido"(case-sensitive) - Required: Yes
- Validation:
z.enum(['Disponible', 'Reservado', 'Alquilado', 'Vendido'])
Partial Updates
For PATCH requests (updating properties), all fields become optional using Zod’s.partial() method:
- You can send any subset of fields
- Only the fields you send will be validated
- Fields not included in the request will remain unchanged in the database
Special Validation Rules
codigo_id on Update
When updating a property via PATCH, thecodigo_id in the request body (if provided) must match the id in the URL path:
Unique codigo_id
When creating a property with a customcodigo_id, it must be unique:
Error Response Format
When validation fails, the API returns a structured error response:Source Code Reference
Validation is implemented using Zod insrc/db/schema.ts:3: