# Orders

A Route is basically a backend REST API, where you write code for some DB Operation or anything else. You make request to this route to get some data or execute any other logic on the server.&#x20;

In order to create a route, fill the following details in the form : -&#x20;

1. Name - name of the route.&#x20;
2. Path – endpoint URL of the route.&#x20;
3. Active – Check / Uncheck if ready / not ready to used.&#x20;
4. Route Type: -\
   MS – route type is microservice.\
   SITE – for serving static content.\
   API – for serving data from database.\
   CORE – core route is for system specific operations.&#x20;
5. Method: -\
   POST – to post some data. \
   GET – to get some data.&#x20;
6. Script – Code goes here.&#x20;
7. Click on ‘create’ button. That’s it, you have created a Route.

/getOrders

Below is the code for getOrders API. In this example we are calling a server script xe.Order which has a method called find which will return the list of all orders.

```javascript
module.exports.getOrders = () => {
  return async (req, res) => {
    const domain = req.subdomains[0] || "dev";
    let _query = { domain };
    res.set("Cache-Control", "no-cache");
    const user = req.user;
    ob.log(_query);
    const orders = await xe.Order.find(_query);
    res.json(orders);
  };
};
```

/postOrder

Below is the code for postOrder API. In this example allows user to make an order. In this code we retrieve the form values storing order details and pass it to a server script called xe.Order which has a method called save which will save the order details ot the database.

```javascript
module.exports.postOrder = () => {
  return async (req, res) => {
    const domain = req.subdomains[0] || "dev";
    const user = req.user;
    const {
      totalAmount,
      customerMobile,
      customerName,
      orderLines,
      studentClass,
      transactionDate
    } = req.body;
    const order = new xe.Order({
      domain,
      status: [{
        state: "Submitted",
        update_on: new Date()
      }],
      totalAmount,
      customerMobile,
      customerName,
      orderLines,
      studentClass,
      transactionDate : new Date(transactionDate),
      created_on: new Date(),
      updated_on: new Date(),
      created_by: user.user_name,
      updated_by: user.user_name
    });

    // Insert the article in our MongoDB database
    await order.save();
    res.json({ success: true });
  };
};
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.obto.co/sofos/order-management/api/orders.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
