Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/nelrondon/backend-proyecto-estructuras/llms.txt

Use this file to discover all available pages before exploring further.

The properties table stores every real estate listing published through the Estructuras platform. Each record captures the full physical and commercial profile of a property — its location, pricing, physical attributes, listing status, and a reference back to the user who created it. The PropiertyModel class provides static async methods that cover the four main read patterns (all, by ID, by status, by type) as well as record creation, with all SQL parameterized to prevent injection.

Database Fields

id
string (UUID)
required
A universally unique identifier generated at creation time via Node.js’s built-in randomUUID() from the node:crypto module. Serves as the primary key for the properties table.
import { randomUUID } from "node:crypto";
const id = randomUUID(); // e.g. "c7e2a1b9-32dc-4f8e-a901-abcdef012345"
title
string
required
A short, human-readable title for the listing (e.g. "Casa en Urbanización Los Pinos"). Must be a string; validated as required by the property schema.
description
string
A free-form text description of the property. Optional in the Zod schema but strongly recommended for complete listings. Must be a string if provided.
status
string enum
required
The commercial availability status of the property. Must be one of the three allowed values: "Venta", "Alquiler", or "Ambas". Any other value is rejected at the schema validation layer with a descriptive error message.
property_type
string enum
required
The structural category of the property. Must be one of the four allowed values: "Casa", "Apartamento", "Terreno", or "Comercial". Any other value is rejected at the schema validation layer.
address
string
required
The street-level address of the property (e.g. "Av. Libertador, Edificio Torre Norte, Piso 3").
city
string
required
The city in which the property is located (e.g. "Caracas").
state
string
required
The state or province in which the property is located (e.g. "Distrito Capital").
price
number
required
The listing price. Must be a numeric value; no currency is enforced at the model level. For rental properties this represents the monthly rent; for sale properties the asking price.
bedrooms
number
The number of bedrooms. Optional; must be a number if provided.
bathrooms
number
The number of bathrooms. Optional; must be a number if provided.
square_feet
number
The total area of the property in square feet. Optional; must be a number if provided.
parking_lots
number
The number of dedicated parking spaces. Optional; must be a number if provided.
img_url
string
A URL pointing to the primary image for the listing (e.g. a cloud storage URL). Optional; not enforced in the current Zod schema but used during INSERT.
user_id
string (UUID)
Foreign key referencing the id of the user who created the listing. Populated automatically from the authenticated session context (userId) when PropiertyModel.register() is called — it is never supplied directly by the client request body.

Enum Values

status — Listing availability

ValueMeaning
VentaThe property is listed for sale only.
AlquilerThe property is listed for rent only.
AmbasThe property is available for both sale and rent.

property_type — Structural category

ValueMeaning
CasaA standalone house or residential dwelling.
ApartamentoA unit within a multi-floor apartment building.
TerrenoAn undeveloped land parcel or lot.
ComercialA commercial space (office, storefront, warehouse, etc.).
Both enums are defined in src/schemas/property.schema.js and enforced via Zod’s z.enum(). Submitting an unlisted value returns a human-readable Spanish error message that lists every valid option.

Validation Rules

All incoming property data is validated through a Zod schema defined in src/schemas/property.schema.js. validateProperty enforces all fields; validatePartialProperty wraps the same schema with .partial() for partial-update use cases.

Model Methods

All methods are static async members of the PropiertyModel class exported from src/models/property.model.js. The database client is the Turso libSQL client imported from src/db.js.

PropiertyModel.getAll()

Returns every property row in the table.
const properties = await PropiertyModel.getAll();
Returns: an array of all property row objects.
Throws: "No hay propiedades" if the properties table contains no records.

PropiertyModel.getById(id)

Returns a single property row matching the given UUID.
const property = await PropiertyModel.getById("c7e2a1b9-32dc-4f8e-a901-abcdef012345");
ParameterTypeDescription
idstringUUID of the property to retrieve
Returns: the matching property row object.
Throws: "Propiedad no encontrada en la base de datos" if no record matches the given id.

PropiertyModel.getByStatus(status)

Returns all properties whose status column matches the given value.
const forSale = await PropiertyModel.getByStatus("Venta");
ParameterTypeAllowed values
statusstring"Venta", "Alquiler", "Ambas"
Returns: an array of property row objects matching the given status.
Throws: "No existen propiedades con este Estado" if no listings have that status.

PropiertyModel.getByType(type)

Returns all properties whose property_type column matches the given value.
const apartments = await PropiertyModel.getByType("Apartamento");
ParameterTypeAllowed values
typestring"Casa", "Apartamento", "Terreno", "Comercial"
Returns: an array of property row objects matching the given type.
Throws: "No hay propiedades de este tipo" if no listings have that property type.

PropiertyModel.register(data)

Inserts a new property listing into the database. The id is generated server-side; the user_id is taken from the authenticated session context rather than the request body.
await PropiertyModel.register({
  title:         "Apartamento en Las Mercedes",
  description:   "Moderno apartamento de 2 habitaciones en zona exclusiva.",
  status:        "Venta",
  property_type: "Apartamento",
  address:       "Calle Veracruz, Edif. Parque Las Mercedes, Piso 5",
  city:          "Caracas",
  state:         "Distrito Capital",
  price:         95000,
  bedrooms:      2,
  bathrooms:     2,
  square_feet:   950,
  parking_lots:  1,
  img_url:       "https://cdn.example.com/properties/apt-las-mercedes.jpg",
  userId:        "a3f1c2d4-89ab-4cde-b012-1234567890ab",
});
ParameterTypeRequiredDescription
data.titlestringYesListing title
data.descriptionstringNoFree-form description
data.statusstringYesOne of the three allowed status enum values
data.property_typestringYesOne of the four allowed type enum values
data.addressstringYesStreet-level address
data.citystringYesCity name
data.statestringYesState or province name
data.pricenumberYesListing price or monthly rent
data.bedroomsnumberNoNumber of bedrooms
data.bathroomsnumberNoNumber of bathrooms
data.square_feetnumberNoTotal area in square feet
data.parking_lotsnumberNoNumber of parking spaces
data.img_urlstringNoURL of the primary listing image
data.userIdstringYesUUID of the authenticated user — set by the controller
Returns: nothing (the method resolves without a return value on success).
Throws: "Error al registrar la Propiedad: <db error>" if the INSERT fails.
The userId parameter comes from the server-side session or JWT payload in the controller layer, not from the request body. This ensures a listing is always attributed to the currently authenticated user and cannot be spoofed by a client.

Example Property Object

The following JSON represents a fully populated property record as it would be returned from PropiertyModel.getById() or any other read method:
{
  "id": "c7e2a1b9-32dc-4f8e-a901-abcdef012345",
  "title": "Casa en Urbanización Los Pinos",
  "description": "Hermosa casa de tres habitaciones con jardín y piscina privada en urbanización cerrada.",
  "status": "Venta",
  "property_type": "Casa",
  "address": "Calle Los Cedros, Casa #14, Urb. Los Pinos",
  "city": "Valencia",
  "state": "Carabobo",
  "price": 175000,
  "bedrooms": 3,
  "bathrooms": 2,
  "square_feet": 2100,
  "parking_lots": 2,
  "img_url": "https://cdn.example.com/properties/casa-los-pinos.jpg",
  "user_id": "a3f1c2d4-89ab-4cde-b012-1234567890ab"
}

Build docs developers (and LLMs) love