E-Commerce API - Admin Only
Documentation
Overview
This document provides details on the admin-only endpoints available in the E-Commerce API.
These routes allow administrators to manage users, products, and orders within the platform. All
admin routes require authentication and authorization using a JWT token with admin privileges.
1. User Management
GET /api/users/all
Description: Retrieves a list of all registered users.
Response:
[
{ /* user data */ },
{ /* user data */ }
]
PUT /api/users/:id/role
Description: Updates a user's role (e.g., promoting to admin).
Request Body:
{
"role": "admin"
}
Response:
{
"message": "User role updated",
"user": { /* updated user data */ }
}
2. Product Management
POST /api/products
Description: Adds a new product to the platform.
Request Body:
{
"name": "Product Name",
"price": 100,
"description": "Product Description"
}
Response:
{
"id": 1,
"name": "Product Name",
"price": 100,
"description": "Product Description"
}
PUT /api/products/:id
Description: Updates an existing product.
Request Body:
{
"name": "Updated Product Name",
"price": 120,
"description": "Updated Description"
}
Response:
{
"id": 1,
"name": "Updated Product Name",
"price": 120,
"description": "Updated Description"
}
DELETE /api/products/:id
Description: Deletes a product from the platform.
Response:
{
"message": "Product deleted"
}
3. Order Management
GET /api/orders
Description: Retrieves a list of all orders placed by users.
Response:
[
{ /* order data */ },
{ /* order data */ }
]
PUT /api/orders/:id
Description: Updates the status of an order (e.g., marking it as shipped).
Request Body:
{
"status": "shipped"
}
Response:
{
"id": 1,
"userId": 1,
"totalAmount": 200,
"status": "shipped"
}
Authentication & Security
All admin routes require authentication and role-based access control (RBAC). Ensure that
requests include a valid JWT token with admin privileges.
Middleware Used:
● authenticate: Ensures the user is logged in by verifying the JWT token.
● authorize("admin"): Restricts access to admin users only.
Summary of Admin-Only Routes
● User Management
○ GET /api/users/all - View all users.
○ PUT /api/users/:id/role - Update user roles.
● Product Management
○ POST /api/products - Add a product.
○ PUT /api/products/:id - Update a product.
○ DELETE /api/products/:id - Delete a product.
● Order Management
○ GET /api/orders - View all orders.
○ PUT /api/orders/:id - Update order status.
This document serves as a reference for administrators managing the e-commerce platform.
Ensure all API calls include the appropriate authentication headers.