def post(self): data = request.json try: user = Users(data["login"], data["password"], data["name"], data["passport"], data["address"], data["email"], data["phone_number"], data["status"]) user.password = generate_password_hash(data['password']) checkuser = session.query(Users).filter( Users.login == user.login).all() if checkuser: return Response(response=json.dumps( {"message": "user with such login already exist"}), status=409, mimetype="application/json") session.add(user) session.flush() session.commit() token = user.get_token() return Response(response=json.dumps({"message": "Success"}), status=200, mimetype="application/json") except: return Response(response=json.dumps({"message": "Invalid input"}), status=405, mimetype="application/json")
def post(self): data = request.json user_id = get_jwt_identity() checkuser = session.query(Users).filter(Users.id == user_id).one() if checkuser.status == "admin": return Response(response=json.dumps( {"message": "Not allowed for admins"}), status=400, mimetype="application/json") try: credit = Credits(data["start_date"], data["end_date"], data["start_sum"], data["current_sum"], data["bank_id"], user_id) session.add(credit) session.commit() usercredit = UserCredit(credit.user_id, credit.id) session.add(usercredit) session.commit() return Response(response=json.dumps({"message": "Success"}), status=200, mimetype="application/json") except: return Response(response=json.dumps({"message": "Invalid input"}), status=405, mimetype="application/json")
def save(self): try: session.add(self) session.commit() except Exception: session.rollback() raise
def create_contact(username="",first_name="",last_name="",email=""): new_contact = Contact( username=username, first_name=ContactFirstName(value=first_name), last_name=ContactLastName(value=last_name), emails=[ContactEmail(value=email)] ) session.add(new_contact) session.commit() return jsonify([x.to_json() for x in session.query(Contact).filter_by(username=f'{username}')])
def post(self, credit_id): data = request.json user_id = get_jwt_identity() checkuser = session.query(Users).filter(Users.id == user_id).one() if checkuser.status == "admin": return Response(response=json.dumps( {"message": "Not allowed for admins"}), status=400, mimetype="application/json") try: transaction = Transactions(data["date"], data["summ"], credit_id) session.add(transaction) session.commit() return Response(response=json.dumps({"message": "Success"}), status=200, mimetype="application/json") except: return Response(response=json.dumps({"message": "Invalid input"}), status=405, mimetype="application/json")
def post(self): data = request.json user_id = get_jwt_identity() checkuser = session.query(Users).filter(Users.id == user_id).one() if checkuser.status != "admin": return Response(response=json.dumps( {"message": "Not allowed for users"}), status=400, mimetype="application/json") try: bank = Banks(data["all_money"], data["per_cent"]) session.add(bank) session.commit() return Response(response=json.dumps({"message": "Success"}), status=200, mimetype="application/json") except: return Response(response=json.dumps({"message": "Invalid input"}), status=405, mimetype="application/json")