Skip to main content

Overview

The User model represents registered users in the Tambo360 platform. Each user can own multiple establishments (dairy farms) and authenticate to access the system.

TypeScript Definition

interface User {
  idUsuario: string;
  correo: string;
  contrasena: string;
  nombre: string;
  verificado: boolean;
  fechaCreacion: Date;
  establecimientos?: Establishment[];
  tokens?: VerificationToken[];
}

Fields

idUsuario
string
required
Unique identifier for the user. Auto-generated UUID.Database: Primary key, UUID format
correo
string
required
User’s email address. Must be unique across the system.Constraints: UniqueUsage: Used for authentication and account verification
contrasena
string
required
User’s hashed password.Security: Should be hashed using bcrypt or similar before storageNote: Never returned in API responses
nombre
string
required
User’s full name or display name.Constraints: Maximum 50 characters (VARCHAR(50))
verificado
boolean
required
Indicates whether the user has verified their email address.Default: falseUsage: Restricts access until email verification is completed
fechaCreacion
datetime
required
Timestamp when the user account was created.Default: Current timestampFormat: ISO 8601 datetime string

Relationships

Example Response

{
  "idUsuario": "a7b8c9d0-1234-5678-90ab-cdef12345678",
  "correo": "[email protected]",
  "nombre": "Juan Pérez",
  "verificado": true,
  "fechaCreacion": "2024-01-15T10:30:00.000Z",
  "establecimientos": [
    {
      "idEstablecimiento": "e1f2g3h4-5678-90ab-cdef-1234567890ab",
      "nombre": "La Esperanza",
      "localidad": "Rafaela",
      "provincia": "Santa Fe"
    }
  ]
}

Usage Notes

Authentication

  • The correo and contrasena fields are used for user login
  • Password should be hashed with bcrypt before comparison
  • verificado status should be checked before granting full access

Security Considerations

  • Never expose the contrasena field in API responses
  • Always exclude password from SELECT queries when returning user data
  • Implement rate limiting on authentication endpoints

Email Verification Flow

  1. User registers with verificado: false
  2. Verification token is created in tokens relation
  3. Email is sent with verification link
  4. Upon verification, verificado is set to true

Build docs developers (and LLMs) love