Skip to main content

Get User Statistics

Retrieve comprehensive workout statistics for a user, including total workouts, current streak, and workout history.

Authentication

Authorization
string
required
Bearer JWT token obtained from login
Users can only access their own statistics. The authenticated user ID must match the :userId parameter.

Path Parameters

userId
string
required
MongoDB ObjectId of the user

Response

success
boolean
Indicates if the request was successful
data
object
Statistics object containing all metrics

Example Request

curl -X GET 'https://api.fitaiid.com/api/estadisticas/507f1f77bcf86cd799439011' \
  -H 'Authorization: Bearer YOUR_JWT_TOKEN'

Example Response

{
  "success": true,
  "data": {
    "totalWorkouts": 45,
    "totalExercises": 340,
    "totalMinutes": 2250,
    "currentStreak": 12,
    "maxStreak": 18,
    "thisWeekWorkouts": 5,
    "thisMonthWorkouts": 18,
    "workoutHistory": [
      {
        "date": "2024-03-05T18:30:00.000Z",
        "dayName": "Día 1 - Pecho y Tríceps",
        "exercises": [
          {
            "nombre": "Press de banca",
            "series": 4,
            "repeticiones": "8-10"
          },
          {
            "nombre": "Press inclinado con mancuernas",
            "series": 3,
            "repeticiones": "10-12"
          }
        ],
        "duration": 50,
        "caloriesBurned": 320
      },
      {
        "date": "2024-03-04T17:15:00.000Z",
        "dayName": "Día 2 - Espalda y Bíceps",
        "exercises": [
          {
            "nombre": "Dominadas",
            "series": 4,
            "repeticiones": "6-8"
          }
        ],
        "duration": 55,
        "caloriesBurned": 340
      }
    ],
    "achievements": [
      {
        "achievementId": "first_workout",
        "unlockedAt": "2024-01-15T10:30:00.000Z"
      },
      {
        "achievementId": "week_streak",
        "unlockedAt": "2024-02-01T18:45:00.000Z"
      },
      {
        "achievementId": "ten_workouts",
        "unlockedAt": "2024-02-10T20:00:00.000Z"
      }
    ]
  }
}

Get Chart Data

Retrieve formatted data for visualizing workout statistics in charts.

Authentication

Authorization
string
required
Bearer JWT token obtained from login

Path Parameters

userId
string
required
MongoDB ObjectId of the user

Response

success
boolean
Indicates if the request was successful
data
object
Chart data organized by visualization type

Example Request

JavaScript
const response = await fetch(
  `https://api.fitaiid.com/api/estadisticas/graficos/${userId}`,
  {
    headers: { 'Authorization': `Bearer ${token}` }
  }
);

const { data } = await response.json();

// Use with Chart.js
const weeklyChart = new Chart(ctx, {
  type: 'bar',
  data: {
    labels: data.weeklyChart.labels,
    datasets: [{
      label: 'Entrenamientos por día',
      data: data.weeklyChart.data
    }]
  }
});

Example Response

{
  "success": true,
  "data": {
    "weeklyChart": {
      "labels": ["Lun", "Mar", "Mié", "Jue", "Vie", "Sáb", "Dom"],
      "data": [8, 7, 9, 8, 6, 4, 3]
    },
    "monthlyChart": {
      "labels": ["Sem 4", "Sem 3", "Sem 2", "Esta semana"],
      "data": [12, 15, 14, 18]
    },
    "focusChart": {
      "labels": ["Pecho", "Espalda", "Piernas", "Hombros", "Brazos"],
      "data": [10, 9, 12, 7, 7]
    },
    "timeChart": {
      "labels": ["Mañana (6-12h)", "Tarde (12-18h)", "Noche (18-24h)"],
      "data": [8, 22, 15]
    }
  }
}

Error Responses

403
error
Unauthorized - User trying to access another user’s statistics
{
  "success": false,
  "message": "No autorizado para acceder a estos datos"
}
404
error
User not found
{
  "success": false,
  "message": "Usuario no encontrado"
}

Implementation Notes

Statistics are calculated in real-time from the user’s fitnessStats field in MongoDB. The streak calculation considers consecutive days with at least one completed workout.
Use the /graficos endpoint specifically for dashboard visualizations. It returns data pre-formatted for Chart.js integration.

Workout History

Get detailed workout history with all exercises

Achievements

View all unlocked achievements

User Profile

Get complete user profile

Build docs developers (and LLMs) love