def update_producto(producto_id): producto = Producto.find_or_fail(producto_id) producto.update(**request.get_json()) return jsonify(producto)
def category_with_diseases(id): return jsonify( db.table('diseases').where('category_id', id).get() )
def category(): category = db.table('categories').get() return jsonify(category), 200
def update_payment(id): db.table('user_orders').where('id', id).update({'purchased': 1}) return jsonify({'message': 'success'}), 200
def update_categories(id): if request.is_json: return jsonify(db.table('categories').where('id', id).update(request.get_json())) else: return jsonify({"ERR": "You must hAve JSON"})
def create_message(user_id): user = User.find_or_fail(user_id) return jsonify(user.messages().create(**request.get_json()))
def create_user(): user = User.create(**request.get_json()) return jsonify(user)
def single(id): return jsonify(db.table('diseases').where('id',id).first())
def disease_treatment(id): d = db.table('diseases').where('id',id).first() return jsonify( d )
def index(): if request.is_json: disease = db.table('diseases').insert(request.get_json()) return jsonify(disease),201 else: return jsonify({"ERR": "You must hAve JSON"})
def update_disease(id): if request.is_json: disease = db.table('diseases').where('id',id).update(request.get_json()) return jsonify(disease) else: return jsonify({"ERR": "You must hAve JSON"})
def about_app(): return jsonify(db.select("select text,contact from about limit 1")[0])
def disease(): sql = "SELECT * , (select categories.name from categories where categories.id = diseases.category_id) as category FROM diseases" alt = db.select(sql) disease = db.table('diseases').get() return jsonify(alt)
def delete_producto(producto_id): producto = Producto.find_or_fail(producto_id) producto.delete() return jsonify(producto)
def get_all_users(): users = User.all() return jsonify(users)
def disease_tests(id): d = db.table('blood_tests').select('name','variable').where('disease_id',id).get() return jsonify( d.serialize() )
def update_user(user_id): user = User.find_or_fail(user_id) user.update(**request.get_json()) return jsonify(user)
def categories_indicators(id): d = db.table('indicators').select('id','name','variable','description','default_unit').where('categories_id',id).get() return jsonify( d.serialize() )
def get_user_followers(user_id): user = User.find_or_fail(user_id) return jsonify(user.followers)
def remove_indicators(id): d = db.table('indicators').where('id',id).delete() return jsonify({'message':'deleted'}),200
def get_recent_diagnosis(id): sql = "SELECT * FROM user_orders WHERE user_id = {} order by id desc limit 1" y = db.select(sql.format(id)) return jsonify(y), 200
def update_message(message_id): message = Message.find_or_fail(message_id) message.update(**request.get_json()) return jsonify(message)
def set_categories(): if request.is_json: category = db.table('categories').insert(request.get_json()) return jsonify(category) else: return jsonify({"ERR": "You must hAve JSON"})
def delete_message(message_id): message = Message.find_or_fail(message_id) message.delete() return jsonify({"result": "message deleted"})
def single_category(id): return jsonify(db.table('categories').where('id', id).first())
def get_message(message_id): message = Message.find_or_fail(message_id) return jsonify(message)
def test_api(): sql = "CALL all_diseases_info()"; return jsonify(db.select(sql)),200
def get_user(user_id): user = User.find_or_fail(user_id) return jsonify(user)
def get_user_messages(user_id): user = User.find_or_fail(user_id) return jsonify(user.messages)
def get_producto(producto_id): producto = Producto.find(producto_id) return jsonify(producto)