示例#1
0
def addOrders():
    """
        DESCRIPTION:
            This route is for adding menu orders to a specific order
        
        REQUEST TYPE: POST

        PARAMETERS:
            list of menu orders to add

        RETURNS:
            redirects the page based on the login role

    """

    #order no is accessed from the session
    #if it doesn't exist then, table is empty
    if 'orderNo' in session:
        orderNo = session['orderNo']
        values = request.get_json(silent=True)
        print(values)
        if Mongo_Client.AddOrders(values, orderNo):
            return json.dumps({"success": True})
        else:
            return json.dumps({"error": "Database Error"})
    else:
        return json.dumps({"error": "Unauthorized"})
示例#2
0
def addOrders(data):
    """
        DESCRIPTION:
            This event is for adding order to a table
        
        PARAMETERS:
            order details

    """
    orderNo = None
    clientOrder = False
    print(data)
    #client made an order
    if 'orderNo' in session:
        clientOrder = True
        orderNo = session['orderNo']
        #waitress made an order
    elif 'orderNo' in data:
        orderNo = data["orderNo"]
    else:
        send("Unauthorized")
        return json.dumps({"error": "Unauthorized"})

    print(loggedInClients)
    print(loggedInServers)
    if Mongo_Client.AddOrders(data["orders"], orderNo):

        #emit to the specific client
        emit("Order Added", {
            "success": True,
            "orders": data["orders"]
        },
             json=True,
             room=loggedInClients[orderNo])
        #emit to all the servers
        for server in loggedInServers:
            print("Sent to", server)
            emit("Order Added", {
                "success": True,
                "data": {
                    "orderNo": orderNo,
                    "orders": data["orders"]
                }
            },
                 json=True,
                 room=server)

    else:
        send("Error")