Overview
Orders Admin API provides comprehensive order management tools for platform administrators. Includes order listing with filtering, status management, revenue analytics, store performance rankings, and bulk delete operations. All functions require admin authorization. Location:convex/admins/ordersAdmin.ts
Get All Orders
Fetches all orders with filtering and cursor-based pagination. Orders are returned newest first, enriched with customer name, store name, and item count. Supports filtering by status, store, customer, date range, and text search (searches customer name, store name, and order ID).string
Filter by order status:
pending, preparing, ready, out_for_delivery, delivered, cancelledId<'stores'>
Filter orders by store. Uses the
by_store index for efficient lookup.Id<'customers'>
Filter orders by customer
string
Text search across customer name, store name, and order ID (case-insensitive)
number
Filter orders created on or after this timestamp (milliseconds)
number
Filter orders created on or before this timestamp (milliseconds)
PaginationOptions
required
Pagination options (numItems, cursor)
Get Store Orders
Fetches orders for a specific store with pagination. Returns enriched orders with customer name, phone number, and item count, plus the store name and total order count.Id<'stores'>
required
Store ID to fetch orders for
string
Filter by order status:
pending, preparing, ready, out_for_delivery, delivered, cancelledPaginationOptions
required
Pagination options (numItems, cursor)
Get Order Status Counts
Returns live order counts grouped by status. Used for dashboard cards showing per-status totals. No arguments required.Get Order Statistics
Returns order statistics from the pre-computedadminOrderStats aggregate table. Supports daily or all-time views.
string
Date in
YYYY-MM-DD format for daily stats. Omit for all-time statistics.When no stats exist for the requested date, all values return as zero. The
averageOrderValue is calculated as totalRevenue / completedOrders.Get Order Details
Fetches full details for a single order, including enriched customer info, store info, order items, and status history timeline.Id<'orders'>
required
Order ID to retrieve
Status history is sorted chronologically (oldest first). Order items already contain
productName and productImage from the original order.Update Order Status
Admin override to update an order’s status. Records the change in theorderStatusHistory table with the admin marked as a system user type.
Id<'orders'>
required
Order ID to update
string
required
New status:
pending, preparing, ready, out_for_delivery, delivered, cancelledstring
Optional notes explaining the status change. Defaults to a generated message.
Get Revenue Analytics
Returns revenue analytics grouped by time period. Only counts delivered (completed) orders.number
required
Start of date range (timestamp in milliseconds)
number
required
End of date range (timestamp in milliseconds)
string
Grouping period:
day, week, or month. Defaults to day.For
week grouping, the period key is the Sunday (start of week) date. For month grouping, the format is YYYY-MM. Results are sorted chronologically.Get Top Stores By Orders
Returns the top performing stores ranked by number of completed (delivered) orders, with revenue metrics.number
Maximum number of stores to return. Defaults to 10.
number
Filter orders created on or after this timestamp (milliseconds)
number
Filter orders created on or before this timestamp (milliseconds)
Bulk Delete Orders
Permanently deletes multiple orders and their associated status history records. Processes in batches of 50 using internal mutations.Id<'orders'>[]
required
Array of order IDs to delete
This is a Convex action that delegates to internal mutations in batches of 50. Each order’s status history entries from
orderStatusHistory are deleted before the order itself. Returns zero counts if an empty array is passed.