Пример #1
0
    def put(self):
        # Make sure user is a manager, waitstaff or customer
        claims = get_jwt_claims()
        order = claims.get('order')
        role = claims.get('role')
        if db.get_staff_title(role) not in ('Manage',
                                            'Wait') and order is None:
            abort(400, 'User is not a waitstaff, manager or customer')

        # Validate the request body
        body = request.get_json()

        bill = body.get('bill')
        order_id = get_jwt_claims().get('order')
        table_id = body.get('table')
        if (not order_id and not table_id):
            abort(400, 'Invalid request')
        elif (not order_id):
            order_id = table_db.get_order_id(table_id)
        elif (not table_id):
            table_id = table_db.get_table_id(order_id)

        if (bill == None or table_id == None):
            abort(400, "Invalid request. Missing required field")

        # Set the request bill status of an order as true/false
        if (table_db.set_bill(table_id, bill) == None):
            abort(500, 'Something went wrong.')

        if bill:
            # Notify waitstaff of bill request
            socket.emit('billrequest', room='staff1')

        return jsonify({'success': 'success'})
Пример #2
0
    def post(self):

        new_order = request.get_json()
        num_of_orders = len(new_order.get('order'))
        order_id = get_jwt_claims().get('order')
        table_id = order_db.get_table_id(order_id)

        if (order_id is None):
            order_id = order_db.insert_order(table_id)

        # Emit to Kitchen Staff that a new order has been placed
        socket.emit('order', {'table': table_id}, room='staff2')

        for i in range(0, num_of_orders):
            item_id = new_order.get('order')[i].get('item_id')
            quantity = new_order.get('order')[i].get('quantity')
            comment = new_order.get('order')[i].get('comment')

            if not comment:
                comment = ""

            new = order_db.insert_item_order(order_id, item_id, quantity,
                                             comment)
            if new is None:
                abort(
                    400,
                    'Backend is not working as intended or the supplied information was malformed. Make sure that your username is unique.'
                )

        return {'status': 'success'}
Пример #3
0
    def delete(self):
        delete_order = request.get_json()
        item_order_id = delete_order.get('id')

        order_id = get_jwt_claims().get('order')
        table_id = order_db.get_table_id(order_id)

        # Socket to send to kitchen staff if order has been deleted
        deletions = 'Table ' + str(table_id) + ' has deleted order ' + str(
            item_order_id)
        socket.emit('delete', {'deletions': deletions}, room='staff2')

        # Error checking if item order ID is incorrect
        if item_order_id is None:
            abort(
                400,
                'No existing order with that item, please make a new order instead.'
            )

        order_status = order_db.get_item_order_status(item_order_id)
        if order_status != 1:
            abort(
                400,
                'Cannot modify order since order has left the QUEUE status.')
        else:
            new = order_db.delete_item_order(item_order_id)

        response = jsonify({'status': 'success'})
Пример #4
0
    def patch(self):

        modify_order = request.get_json()
        item_order_id = modify_order.get('item_id')
        quantity = modify_order.get('quantity')
        comment = modify_order.get('comment')
        order_id = get_jwt_claims().get('order')
        table_id = order_db.get_table_id(order_id)

        # String to send modifications notification to backend
        modifications = 'Table ' + str(
            table_id) + ' has modified order ' + str(item_order_id)
        print(modifications)
        socket.emit('modify', {'modifications': modifications}, room='staff2')

        # If order ID is empty, send error message to create new order
        if item_order_id is None:
            abort(
                400,
                'No existing order with that item, please make a new order instead.'
            )

        new = order_db.modify_item_order(item_order_id, comment, quantity)
        if new == 5:
            abort(
                400,
                'New quantity has to be >= 1 OR order has left the QUEUE status, please make a NEW order instead.'
            )

        response = jsonify({'status': 'success'})
Пример #5
0
    def post(self, table):
        # Make sure user is a manager or waitstaff
        role = get_jwt_claims().get('role')
        if db.get_staff_title(role) not in ('Manage', 'Wait'):
            abort(400, 'User is not a waitstaff or manager')

        # Set table free
        if (not table_db.set_table_free(table)):
            abort(500, 'Something went wrong')

        print('Table #' + str(table) + ' set occupied as false')

        # get the latest orderid of table
        order_id = table_db.get_order_id(table)
        customerRoom = 'customer' + str(order_id)
        print(customerRoom)
        # Notify customer that they have paid successfully
        socket.emit('paid', room=customerRoom)

        return jsonify({'status': 'success'})
Пример #6
0
    def put(self):
        # Make sure user is a manager, waitstaff or customer
        claims = get_jwt_claims()
        order_id = claims.get('order')
        role = claims.get('role')

        if db.get_staff_title(role) not in ('Manage',
                                            'Wait') and order_id is None:
            abort(400, 'User is not a waitstaff, manager or customer')

        body = request.get_json()

        # Validate request and determine order_id and table_number
        assistance = body.get('assistance')
        table_id = body.get('table')

        if (order_id is None and table_id is None):
            abort(400, 'Invalid request')
        elif (order_id is None):
            order_id = table_db.get_order_id(table_id)
        elif (table_id is None):
            table_id = table_db.get_table_id(order_id)

        if (order_id is None or table_id is None):
            abort(401, 'Unauthorised')

        if (assistance != True and assistance != False):
            abort(400, 'Invalid request')

        # Update assistance
        if (not table_db.set_assistance(table_id, assistance)):
            abort(400, 'Something went wrong')

        # Notify waitstaff
        if (assistance):
            socket.emit('assistance', {'table': table_id}, room='staff1')

        return jsonify({'status': 'success'})
Пример #7
0
    def put(self):
        # Make sure user is a manager or waitstaff
        role = get_jwt_claims().get('role')
        if db.get_staff_title(role) not in ('Manage', 'Wait'):
            abort(400, 'User is not a waitstaff or manager')

        body = request.get_json()

        # Validate request body
        paid = body.get('paid')
        table = body.get('table')
        if (paid == None or table == None):
            abort(400, "Invalid request. Missing required field")

        # Update payment status
        if (table_db.set_paid(table, paid) == None):
            abort(500, 'Something went wrong.')

        # Notify customer that table is paid
        customerRoom = 'customer' + str(table)
        socket.emit('paid', room=customerRoom)

        return jsonify({'success': 'success'})
Пример #8
0
    def put(self, item_order_id):
        status = request.get_json().get('status')
        print('the status is ' + str(status))
        if (not status):
            abort(400, 'Invalid request. Missing required field \'status\'')

        if (not order_db.update_item_ordered_status(item_order_id, status)):
            abort(500, 'Something went wrong')
        print('item_id is ' + str(item_order_id))

        # Sends notification that an order is cooking, ready or server to the customer
        order_id = order_db.get_orderId(item_order_id)
        print('item_id is ' + str(order_id))
        customerRoom = 'customer' + str(order_id)
        if status == 2:
            print('customer room is ' + customerRoom)
            socket.emit('cooking', room=customerRoom)
            socket.emit('cooking', room='staff1')
            socket.emit('cooking', room='staff2')
            print('we have emitted to ' + customerRoom)
        elif status == 3:
            socket.emit('ready', room=customerRoom)
            socket.emit('ready', room='staff1')
            socket.emit('ready', room='staff2')
            print('we have emitted to ' + customerRoom)
        elif status == 4:
            socket.emit('served', room=customerRoom)
            socket.emit('served', room='staff1')
            socket.emit('served', room='staff2')
            print('we have emitted to ' + customerRoom)

        return jsonify({'status': 'success'})