Skip to main content
GET
/
api
/
admin
/
stats
Get Dashboard Statistics
curl --request GET \
  --url https://api.example.com/api/admin/stats
{
  "success": true,
  "data": {
    "totalProperties": 150,
    "activeProperties": 120,
    "salesProperties": 75,
    "rentalProperties": 45,
    "recentProperties": 120,
    "totalUsers": 50
  }
}

Overview

Retrieves comprehensive dashboard statistics for administrators. This endpoint provides key metrics about properties and users in the system.
This endpoint requires admin role authentication via the requireAdmin middleware.

Authentication

Requires an authenticated user with admin role. Include a valid session cookie or authentication token.

Response

Returns aggregated statistics calculated in parallel for optimal performance.
success
boolean
required
Indicates if the request was successful
data
object
required
Statistics object containing the following metrics:
{
  "success": true,
  "data": {
    "totalProperties": 150,
    "activeProperties": 120,
    "salesProperties": 75,
    "rentalProperties": 45,
    "recentProperties": 120,
    "totalUsers": 50
  }
}

Implementation Details

  • All statistics are fetched in parallel using Promise.all() for optimal performance
  • Active properties are filtered by statusId = 1
  • Operation types: 1 = venta (sale), 2 = alquiler (rent)
  • Returns 500 status code on server errors

Error Responses

success
boolean
Will be false when an error occurs
message
string
Error description (e.g., “Failed to fetch statistics”)

Build docs developers (and LLMs) love