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'})
def get(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') # Get current order_id of the table order_id = table_db.get_order_id(table) # Make sure order_id exists if (not order_id): abort(400, 'No orders for this table') # Get items ordered in the table's current session order_items = table_db.get_ordered_items(order_id) if (order_items is None): abort(500, 'Something went wrong') # Calculate total cost of items ordered on current table session total_cost = 0 for item in order_items: total_cost += item['quantity'] * item['price'] return jsonify({ 'table': table, 'order_id': order_id, 'items': order_items, 'total_cost': total_cost })
def post(self): # Create a new menu item role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Get and validate request body item = request.get_json() if not (item.get('name') and item.get('price')): abort(400, 'Request missing required fields') if item.get('visible') is None: item['visible'] = True if item.get('description') is None: item['description'] = '' if item.get('image_url') is None: item['image_url'] = '' # Create new item in db item_id = menu_db.create_item(item) if (not item_id): abort(500, 'Something went wrong') return jsonify({'item_id': item_id})
def get(self): # Make sure user is a manager role = get_jwt_claims().get('role') if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Gets lists of staffs and all their details staff_list = profile_db.get_all_staff() return {'staff_list': staff_list}
def delete(self): # Make sure user is a manager role = get_jwt_claims().get('role') if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Delete table if (not table_db.delete_table()): abort(500, 'Failed to delete table') return jsonify({'status': 'success'})
def delete(self, category_id, item_id): # Remove an item from a category role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') if (not menu_db.remove_item_from_category(category_id, item_id)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def post(self, category_id, item_id): # Add an item to a category role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') if (not menu_db.add_item_to_category(category_id, item_id)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def get(self): # Make sure user is a manager role = get_jwt_claims().get('role') if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Amount of sales for each category category_sales = stats_db.get_category_sales() if (category_sales is None): abort(500, 'Something went wrong') return jsonify({'category_sales': category_sales})
def get(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') # Get tables that require assistance tables = table_db.get_assistance_tables() if (tables is None): abort(500, 'Something went wrong') return jsonify({'tables': tables})
def delete(self, item_id): # Delete a specific menu item role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') if (not menu_db.delete_item(item_id)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def get(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(401, 'User is not a waitstaff or manager') # Return a list of tables that have paid paid = table_db.get_bill_tables() if (paid == None): abort(500, 'Something went wrong') return jsonify({'tables': paid})
def get(self, item_id): # Make sure user is a manager role = get_jwt_claims().get('role') if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Amount of sales for each item item_sales = stats_db.get_menu_item_sales(item_id)[0] if (item_sales is None): abort(500, 'Something went wrong') return jsonify(item_sales)
def delete(self, item_id, ingredient_id): # Remove ingredient from an item role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Remove ingredeint from item in the database if (not menu_db.remove_ingredient_from_item(item_id, ingredient_id)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def delete(self, id): # Delete a specific ingredient # Only if not used role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') if (not menu_db.delete_ingredient(id)): abort(500, 'Ingredient still in use') return jsonify({'status': 'success'})
def post(self, item_id, ingredient_id): # Add an ingredient to an item role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Add ingredient to item in the database if (not menu_db.add_ingredient_to_item(item_id, ingredient_id)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def put(self, category_id): # Edit a category role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') edit = request.get_json() # Edit the category in the database if (not menu_db.edit_category(edit)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def patch(self): # Make sure user is a manager role = get_jwt_claims().get('role') if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Edit staff details edit_staff_input = request.get_json() # get json input for new details staff_id = edit_staff_input.get('staff_id') name_new = edit_staff_input.get('name') username_new = edit_staff_input.get('username') staff_type_id_new = edit_staff_input.get('staff_type_id') staff_curr = profile_db.get_staff_detail( staff_id) # get the current staff's details curr_name = staff_curr['name'] curr_username = staff_curr['username'] curr_staff_type_id = staff_curr['staff_type'] if staff_id == 0: abort(400, 'Please insert a staff id.') # if user doesn't input new name OR username OR staff_type_id, use old (current) ones if name_new == 'string': name = curr_name else: name = name_new regex = re.compile('[@_!#$%^&*()<>?/\|}{~:]') if (regex.search(name) != None): # name cannot contain any special characters abort(400, 'Malformed request, name cannot have special characters') if username_new == 'string': username = curr_username else: username = username_new if staff_type_id_new == 0: staff_type = curr_staff_type_id else: staff_type = staff_type_id_new edit = profile_db.modify_staff(staff_id, name, username, staff_type) if edit != 1: abort(400, 'Something is wrong.') response = jsonify({'status': 'success'})
def put(self, item_id): # Modify a menu item role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Get and validate request body edit = request.get_json() if (not menu_db.edit_item(edit, item_id)): abort(400, 'Something went wrong') return jsonify({'status': 'success'})
def post(self): # Make sure user is a manager role = get_jwt_claims().get('role') if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Validate table number from payload table = request.get_json().get('table') if (not table): abort(400, 'Table number not provided') # Create new table if (not table_db.create_table(table)): abort(500, 'Failed to add table') return jsonify({'status': 'success'})
def post(self, category_id1, category_id2): # Swap position of two categories role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Maintain the correct order when passing in arguments id1 = min(category_id1, category_id2) id2 = max(category_id1, category_id2) if (not menu_db.swapCategoryPositions(id1, id2)): abort(500, 'Failed to swap category positions') return jsonify({'status': 'success'})
def post(self): # Create a new category in the menu role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Get and validate request body name = request.get_json().get('name') if (not name): abort(400, 'Missing required field \'name\'') # Create new category in the database if (not menu_db.create_category(name)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def post(self): # Create a new ingredient role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Validate request body name = request.get_json().get('name') if (not name): abort(400, 'Missing ingredient name') # Create new ingredient item if (not menu_db.create_ingredient(name)): abort(400, 'Something went wrong') return jsonify({'status': 'success'})
def put(self, id): # Modify a specific ingredient role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Validate request body name = request.get_json().get('name') if (not name): abort(400, 'Invalid request') # Edit ingredient in the menu if (not menu_db.edit_ingredient(name, id)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def delete(self, category_id): # Delete a category from the menu role = get_jwt_claims().get('role') # Make sure user is a manager if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') items = menu_db.get_items_by_category(category_id) if items is None: abort(500, 'Something went wrong') elif (len(items) > 0): abort(400, 'Can only delete empty category') # Delete a category if (not menu_db.delete_category(category_id)): abort(500, 'Something went wrong') return jsonify({'status': 'success'})
def delete(self): # Make sure user is a manager role = get_jwt_claims().get('role') if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Delete staff record delete_order = request.get_json( ) # get staff_id to be deleted from json input staff_id = delete_order.get('staff_id') if staff_id == 0: abort(400, 'Please insert staff id.') delete = profile_db.delete_staff(staff_id) if delete != 1: abort(400, 'Something is wrong.') response = jsonify({'status': 'success'})
def get(self): # Make sure user is a manager role = get_jwt_claims().get('role') if db.get_staff_title(role) != 'Manage': abort(400, 'User is not a manager') # Amount of sales for each item item_sales = stats_db.get_menu_item_sales() if (item_sales is None): abort(500, 'Something went wrong') # Sum up revenues total_revenue = 0 for item in item_sales: total_revenue += item['revenue'] return jsonify({ 'item_sales': item_sales, 'total_revenue': total_revenue })
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'})
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'})
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'})