Order Status Management
updatePaymentStatus
Updates the payment status of an order.orderId(number): Order IDstatus(string): New payment status- Common values:
pending,paid,failed,refunded,canceled
- Common values:
conn(PoolClient, optional): Database connection (for transactions)
- Validates status against configured payment statuses
- Updates order payment status
- Can be called within a transaction by passing connection
- Throws error if invalid status provided
pending: Payment not yet receivedpaid: Payment completed successfullyfailed: Payment attempt failedrefunded: Payment refunded to customercanceled: Payment cancelled
updateShipmentStatus
Updates the shipment status of an order.orderId(number): Order IDstatus(string): New shipment status- Common values:
pending,processing,shipped,delivered,canceled
- Common values:
conn(PoolClient, optional): Database connection (for transactions)
pending: Awaiting processingprocessing: Being prepared for shipmentshipped: Shipped to customerdelivered: Delivered to customercanceled: Shipment cancelled
Order Operations
cancelOrder
Cancels an order and restocks inventory.uuid(string): Order UUIDreason(string, optional): Cancellation reason
- Validates order exists
- Checks if order is cancelable based on current status
- Updates payment status to
canceled - Updates shipment status to
canceled - Adds activity log with cancellation reason
- Restocks inventory for all order items
- Commits transaction or rolls back on error
- Order not found
- Order status is not cancelable
- Database transaction fails
Shipment Management
createShipment
Creates a shipment record for an order and updates status to shipped.orderUuid(string): Order UUIDcarrier(string|null): Shipping carrier name- Examples:
'UPS','FedEx','USPS','DHL'
- Examples:
trackingNumber(string|null): Tracking number from carrierconnection(PoolClient, optional): Database connection for transactions
shipment_id(number): Shipment IDshipment_order_id(number): Order IDcarrier(string): Carrier nametracking_number(string): Tracking numbercreated_at(timestamp): Creation timestamp
- Validates order exists
- Checks if shipment already created
- Creates shipment record
- Updates order shipment status to
shipped - Adds order activity log
- Commits transaction
- Order not found
- Shipment already exists
- Database transaction fails
Order Activity
addOrderActivityLog
Adds an activity log entry to an order.orderId(number): Order IDmessage(string): Activity messagecustomerNotified(boolean): Whether customer can see this activityconnection(PoolClient, optional): Database connection for transactions
Order Status Resolution
The OMS module automatically resolves the overall order status based on payment and shipment status combinations. Status Resolution Logic:Query Builder Services
getOrdersBaseQuery
Returns the base query builder for orders.- Order items
- Customer information
- Addresses (shipping and billing)
- Shipment details
- Order activities