Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/floriansalvi/HEIG-VD_Ocha-api/llms.txt

Use this file to discover all available pages before exploring further.

The Get Order Statistics endpoint aggregates all orders in the database and groups the results by user, returning the total number of orders placed and the total amount spent in Swiss francs for each user. The data is computed server-side using a MongoDB aggregation pipeline that groups, looks up the associated user document, and projects a clean summary object.
This endpoint requires admin privileges. Requests authenticated with a regular user JWT will receive a 403 Forbidden response.

HTTP method and path

GET /api/v1/order-stats

Request parameters

Headers

Authorization
string
required
Bearer token for an admin user. Format: Bearer <admin_token>.
This endpoint accepts no query or path parameters.

Response fields

200 OK

stats
object[]
Array of per-user aggregation results. One entry per user who has placed at least one order.

Error codes

StatusMeaning
401Missing or invalid JWT token.
403Authenticated user does not have admin privileges.
500Unexpected server error or aggregation pipeline error.

Example

curl --request GET \
  --url https://api.example.com/api/v1/order-stats \
  --header 'Authorization: Bearer <admin_token>'
{
  "stats": [
    {
      "userId": "64f1c2e9a1b2c3d4e5f00001",
      "user": "Alice",
      "totalOrders": 5,
      "totalSpent": 47.30
    },
    {
      "userId": "64f1c2e9a1b2c3d4e5f00002",
      "user": "Bob",
      "totalOrders": 2,
      "totalSpent": 13.80
    }
  ]
}

Build docs developers (and LLMs) love