Get All Orders
Retrieve all orders with populated user and product information. Orders are sorted by creation date (newest first).Authentication
Requires Clerk authentication with admin role. All admin routes are protected byprotectRoute and adminOnly middleware.
Response
Array of order objects
MongoDB ObjectId
Populated user object with name and email
Clerk user ID
Total order price
Order status (see status enum below)
ISO 8601 timestamp when order was marked as paid
ISO 8601 timestamp when order was delivered
ISO 8601 timestamp
ISO 8601 timestamp
Update Order Status
Update the status of an order. Triggers automated email notifications and invoice generation based on the new status.Authentication
Requires Clerk authentication with admin role.Path Parameters
MongoDB ObjectId of the order to update
Request
New order status. Must be one of:
pending- Order created but not paidpaid- Payment received (triggers invoice generation)in_preparation- Order is being preparedready- Order ready for pickup/deliverydelivered- Order delivered to customercanceled- Order canceledrejected- Order rejected
Response
Success message
The updated order object with populated user and product data
Automated Actions
When the status changes, the following automated actions occur:Status: paid
- Sets
paidAttimestamp if not already set - Generates PDF invoice using
generateInvoicePDF() - Generates CSV invoice using
generateInvoiceCSV() - Sends invoice emails to customer and admin via
sendInvoiceEmails() - Invoice number format:
FV-{YEAR}-{ORDER_ID_SUFFIX} - Payment method inferred from
paymentResult.idprefix:pi_= Stripetransfer_= Transferencia
Status: delivered
- Sets
deliveredAttimestamp if not already set - Sends status update emails to customer and admin
All Other Status Changes
- Sends status update emails to customer (via
sendOrderUpdatedClientEmail()) and admin (viasendOrderUpdatedAdminEmail()) - Respects user’s
emailNotificationspreference
Error Responses
Get Dashboard Statistics
Retrieve aggregated statistics for the admin dashboard including total revenue, orders, customers, and products.Authentication
Requires Clerk authentication with admin role.Response
Total revenue from all orders (sum of all order
totalPrice fields)Total number of orders in the system
Total number of registered users
Total number of products in the catalog
Example Request
Example Response
The
totalRevenue is calculated by aggregating the totalPrice field from all orders, regardless of order status. This includes pending, paid, and delivered orders.