Skip to main content

Introduction

The Maintenance API provides comprehensive endpoints for managing vehicle maintenance operations including:
  • Maintenance Plans: Define scheduled maintenance plans with conditions based on time, kilometers, or hours
  • Maintenance Events: Record actual maintenance activities performed on vehicles
  • Schedule Management: Track upcoming maintenance based on plan conditions
  • Workshop Management: Manage workshop/taller information for maintenance services

Authentication

All maintenance endpoints require authentication using a Bearer token:
Authorization: Bearer YOUR_ACCESS_TOKEN
The authentication is handled by the authMiddleware which validates the JWT token and attaches user information to the request.

Base URL

/api/mantenimiento

Core Concepts

Maintenance Plans (PlanMantenimiento)

Maintenance plans define scheduled maintenance requirements for vehicles. Each plan:
  • Is associated with a specific vehicle
  • Has a maintenance type (preventive, corrective, etc.)
  • Contains one or more conditions that trigger the maintenance
  • Can be activated or deactivated

Plan Conditions (PlanCondicion)

Conditions define when maintenance should be performed:
  • Time-based: Based on calendar dates (e.g., every 6 months)
  • Kilometer-based: Based on distance traveled (e.g., every 5000 km)
  • Hour-based: Based on engine hours (e.g., every 250 hours)

Maintenance Events (MantenimientoEvento)

Events record actual maintenance activities:
  • Linked to a maintenance plan (optional)
  • Include date, cost, and workshop information
  • Record current kilometer and hour readings
  • Support detailed descriptions and observations

Available Endpoints

Maintenance Plans

  • GET /planes - List maintenance plans
  • POST /planes - Create a new maintenance plan
  • PUT /planes/:id - Update a maintenance plan

Maintenance Events

  • GET /eventos - List maintenance events
  • POST /eventos - Create a new maintenance event
  • PUT /eventos/:id - Update a maintenance event
  • DELETE /eventos/:id - Delete a maintenance event

Supporting Data

  • GET /tipos - List maintenance types
  • POST /tipos - Create a new maintenance type
  • GET /condiciones - List condition types
  • GET /proximos - Get upcoming maintenance schedule
  • GET /talleres - List workshops/talleres

Data Models

PlanMantenimiento

interface PlanMantenimiento {
  id: number;
  vehiculo_id: number;
  tipo_mantenimiento_id: number;
  nombre: string;
  activo: boolean;
  vehiculo?: Vehiculo;
  tipo_mantenimiento?: TipoMantenimiento;
  condiciones?: PlanCondicion[];
}

MantenimientoEvento

interface MantenimientoEvento {
  id: number;
  plan_id: number;
  vehiculo_id: number;
  fecha: string;
  descripcion: string | null;
  taller_id: number | null;
  costo: number | null;
  hr_evento: number | null;
  km_evento: number | null;
  observaciones: string | null;
  plan_mantenimiento?: PlanMantenimiento;
  vehiculo?: Vehiculo;
  talleres?: { nombre: string };
}

PlanCondicion

interface PlanCondicion {
  id: number;
  plan_id: number;
  tipo_condicion_id: number;
  valor: number;
  unidad: string;
  tipo_condicion?: TipoCondicion;
}

Quick Start Examples

Create a Maintenance Plan

curl -X POST https://api.example.com/api/mantenimiento/planes \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "vehiculo_id": 123,
    "tipo_mantenimiento_id": 1,
    "nombre": "Mantenimiento Preventivo 10K",
    "activo": true,
    "condiciones": [
      {
        "tipo_condicion_id": 1,
        "valor": 10000,
        "unidad": "km"
      }
    ]
  }'

Record a Maintenance Event

curl -X POST https://api.example.com/api/mantenimiento/eventos \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "vehiculo_id": 123,
    "plan_id": 45,
    "fecha": "2026-03-04",
    "km_evento": 15000,
    "hr_evento": 500,
    "descripcion": "Cambio de aceite y filtros",
    "taller_id": 5,
    "costo": 150000
  }'

Get Upcoming Maintenance

curl -X GET "https://api.example.com/api/mantenimiento/proximos" \
  -H "Authorization: Bearer YOUR_TOKEN"

Error Handling

The API returns standard HTTP status codes:
  • 200 OK - Successful GET/PUT request
  • 201 Created - Successful POST request
  • 204 No Content - Successful DELETE request
  • 400 Bad Request - Invalid request data
  • 500 Internal Server Error - Database or server error
Error responses include detailed information:
{
  "error": "Database error",
  "message": "Detailed error message",
  "details": "Additional error details"
}

Build docs developers (and LLMs) love