The getOrderStatus tool retrieves the current status information for a specific order by its numeric order ID from the Firebase/Firestore database.
tools/getOrderStatus.js
Retrieves essential status information for an order by searching for it using the orderId field (not the document ID). This is a lightweight alternative to getOrderById when you only need status information.
{
orderId: number; // REQUIRED: Numeric order ID (not document ID)
}
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
orderId |
number | Yes | - | Numeric order ID to search for |
{
status: OrderStatus | ErrorStatus;
}
{
orderId: number; // The order ID
stage: number; // Current stage/status number
closed: boolean; // Whether the order is closed
title: string; // Order title
}
{
error: "not-found";
message: string; // Error message
}
// Get status for order with ID 1234
const result = await getOrderStatus(context, {
orderId: 1234
});
if (result.status.error) {
console.log(result.status.message); // "Order with ID 1234 not found."
} else {
console.log(`Order #${result.status.orderId}: ${result.status.title}`);
console.log(`Stage: ${result.status.stage}`);
console.log(`Closed: ${result.status.closed}`);
}
const result = await getOrderStatus(context, {
orderId: 1234
});
if (!result.status.error && result.status.closed) {
console.log("This order is closed");
} else if (!result.status.error) {
console.log(`Order is open, currently at stage ${result.status.stage}`);
}
const result = await getOrderStatus(context, {
orderId: 9999
});
if (result.status.error === "not-found") {
console.log("Order does not exist");
} else {
console.log("Order found:", result.status);
}
Unlike getOrderById, this tool searches by the orderId field rather than document ID:
const ordersRef = collection(db, "Accounts", accountId, "Orders");
const q = query(ordersRef, where("orderId", "==", Number(orderId)));
const snapshot = await getDocs(q);
Returns only essential status fields:
return {
status: {
orderId: orderData.orderId,
stage: orderData.stage,
closed: orderData.closed,
title: orderData.title,
},
};
The tool validates that orderId is provided:
if (orderId === undefined || orderId === null) {
throw new Error("The 'orderId' parameter is required.");
}
Returns a structured error response when order is not found:
if (snapshot.empty) {
return {
status: {
error: "not-found",
message: `Order with ID ${orderId} not found.`,
},
};
}
| Error | Cause | Solution |
|---|---|---|
| “The ‘orderId’ parameter is required.” | Missing orderId | Provide orderId in params |
| “Failed to fetch status for order [id].” | Firestore error | Check Firebase connection and permissions |
When an order is not found, the tool returns a structured error object instead of throwing:
{
status: {
error: "not-found",
message: "Order with ID 1234 not found."
}
}
Firestore errors are logged and re-thrown:
catch (error) {
console.error(`Error fetching status for order ${orderId}:`, error);
throw new Error(`Failed to fetch status for order ${orderId}.`);
}
orderId field which should be indexed in productionUse getOrderStatus when:
Use getOrderById when:
/Accounts/{accountId}/Orders/{documentId}
- orderId: number (queried field)
- stage: number
- closed: boolean
- title: string
- ... other fields