Skip to main content
GET
/
api
/
recognition
/
stats
/
:employeeId
Employee Game Stats
curl --request GET \
  --url https://api.example.com/api/recognition/stats/:employeeId
{
  "success": true,
  "message": "<string>",
  "data.stats": {
    "totalPoints": 123,
    "totalRecognitions": 123,
    "badges": [
      {}
    ],
    "level": 123,
    "recentAchievements": [
      {
        "_id": "<string>",
        "recognitionType": "<string>",
        "title": "<string>",
        "description": "<string>",
        "pointsAwarded": 123,
        "badgeEarned": "<string>",
        "issuedAt": "<string>"
      }
    ]
  }
}

Overview

Retrieve comprehensive gamification statistics for an employee, including total points, level, badges earned, and recent achievements.

Authentication

This endpoint requires authentication.
Authorization: Bearer YOUR_JWT_TOKEN

Endpoint

GET /api/recognition/stats/:employeeId

Path Parameters

employeeId
string
required
The MongoDB ObjectId of the employee

Response

success
boolean
Indicates if the request was successful
message
string
Response message
data.stats
object
Gamification statistics object

Level System

Employee levels are calculated based on total points (src/services/recognitionService.js:116):
LevelPoints Required
10 - 49
250 - 149
3150 - 299
4300 - 499
5500+

Examples

curl -X GET https://api.cuido.com/api/recognition/stats/65a1b2c3d4e5f6a7b8c9d0e2 \
  -H "Authorization: Bearer YOUR_JWT_TOKEN"

Response Example

{
  "success": true,
  "message": "Estadísticas de gamificación obtenidas",
  "data": {
    "stats": {
      "totalPoints": 325,
      "totalRecognitions": 18,
      "badges": [
        "participativo",
        "aprendiz",
        "estrella"
      ],
      "level": 4,
      "recentAchievements": [
        {
          "_id": "65a1b2c3d4e5f6a7b8c9d0e7",
          "recognitionType": "empleado_mes",
          "title": "¡Empleado del Mes!",
          "description": "Reconocimiento por tu excelente desempeño",
          "pointsAwarded": 100,
          "badgeEarned": "estrella",
          "issuedAt": "2024-01-15T10:30:00.000Z"
        },
        {
          "_id": "65a1b2c3d4e5f6a7b8c9d0e8",
          "recognitionType": "curso_terminado",
          "title": "¡Curso Completado!",
          "description": "Has terminado exitosamente tu capacitación",
          "pointsAwarded": 20,
          "badgeEarned": "aprendiz",
          "issuedAt": "2024-01-10T14:20:00.000Z"
        },
        {
          "_id": "65a1b2c3d4e5f6a7b8c9d0e9",
          "recognitionType": "curso_terminado",
          "title": "¡Curso Completado!",
          "description": "Has terminado exitosamente tu capacitación",
          "pointsAwarded": 20,
          "badgeEarned": "aprendiz",
          "issuedAt": "2024-01-05T09:15:00.000Z"
        },
        {
          "_id": "65a1b2c3d4e5f6a7b8c9d0ea",
          "recognitionType": "encuesta_completada",
          "title": "¡Encuesta Completada!",
          "description": "Gracias por compartir tu feedback semanal",
          "pointsAwarded": 5,
          "badgeEarned": "participativo",
          "issuedAt": "2024-01-02T11:30:00.000Z"
        },
        {
          "_id": "65a1b2c3d4e5f6a7b8c9d0eb",
          "recognitionType": "encuesta_completada",
          "title": "¡Encuesta Completada!",
          "description": "Gracias por compartir tu feedback semanal",
          "pointsAwarded": 5,
          "badgeEarned": "participativo",
          "issuedAt": "2023-12-28T08:45:00.000Z"
        }
      ]
    }
  }
}

Calculation Logic

The stats service (src/services/recognitionService.js:98) performs:
  1. Query all recognitions for the employee
  2. Sum points: Reduce all pointsAwarded values
  3. Count recognitions: Total array length
  4. Extract unique badges: Filter and deduplicate badgeEarned values
  5. Calculate level: Apply level formula based on total points
  6. Get recent: Slice last 5 achievements

Use Cases

  1. Employee Dashboard: Display personal gamification progress
  2. Leaderboards: Compare stats across employees
  3. Progress Tracking: Motivate employees to reach next level
  4. Achievement Showcase: Display badges and recent wins
  5. HR Analytics: Track engagement through gamification metrics

Error Responses

{
  "success": false,
  "message": "No autorizado. Token inválido o expirado."
}
For hospital-wide rankings, use:
  • GET /api/recognition/ranking/:hospitalId - Get top employees by points

Frontend Integration Tips

// Display progress to next level
function getNextLevelProgress(stats) {
  const levelThresholds = [0, 50, 150, 300, 500];
  const currentLevel = stats.level;
  const currentPoints = stats.totalPoints;
  
  if (currentLevel === 5) {
    return { progress: 100, pointsToNext: 0 };
  }
  
  const currentThreshold = levelThresholds[currentLevel - 1];
  const nextThreshold = levelThresholds[currentLevel];
  const pointsInLevel = currentPoints - currentThreshold;
  const pointsNeeded = nextThreshold - currentThreshold;
  
  return {
    progress: (pointsInLevel / pointsNeeded) * 100,
    pointsToNext: nextThreshold - currentPoints
  };
}

Source Code References

  • Route: src/routes/recognitionRoutes.js:21
  • Controller: src/controllers/recognitionController.js:25
  • Service: src/services/recognitionService.js:97
  • Level Calculation: src/services/recognitionService.js:116
  • Model: src/models/Recognition.js

Build docs developers (and LLMs) love