def get_cart_for_user(): accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") return auth_user(db, username, accessToken) \ .then(carts.get_cart_for_user) \ .as_dict()
def set_item_data(): accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") return auth_user(db, username, accessToken, 1) \ .then(read_item_data) \ .then(save_item_data) \ .as_dict()
def delete_item(): accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") item_id = request.args.get('itemId', 0, type=int) return auth_user(db, username, accessToken, 1) \ .then(lambda u: products.remove_product(item_id)) \ .as_dict()
def create_item(): accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") return auth_user(db, username, accessToken, 1) \ .then(read_item_data) \ .then(create_item_object) \ .then(lambda p: None) \ .as_dict()
def load_image(): accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") product_id = request.args.get('productId', -1, type=int) return auth_user(db, username, accessToken, 1) \ .then(lambda u: images.load_image(product_id, request.data)) \ .as_dict()
def order_cart(): accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") return auth_user(db, username, accessToken) \ .then(carts.order) \ .peek(lambda a: mailer.notify_ordered(a[0])) \ .then(lambda a: a[1]) \ .as_dict()
def remove_item_from_cart(): accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") batchId = request.args.get('batchId', 0, type=int) return auth_user(db, username, accessToken, 0) \ .then(lambda u: carts.remove_item_from_cart(batchId, u)) \ .as_dict()
def get_order_for_user(): accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") return auth_user(db, username, accessToken) \ .then(lambda u: {"items": carts.get_orders(u), "type": "normal" if u.permission_level == 0 else "super"}) \ .as_dict()
def add_item_to_cart(): item_id = request.args.get("itemId", -1, type=int) accessToken = request.headers.get('accessToken', "") username = request.headers.get('username', "") amount = request.args.get('amount', 0, type=int) return auth_user(db, username, accessToken) \ .then(lambda u: carts.add_item_to_cart(item_id, u, amount)) \ .as_dict()