def item_uncompleted(task_id) -> dict: session = db_session.create_session() task = session.query(Task).get(task_id) if task is None: return jsonify({"status": "Failed"}) task.completed = False session.commit()
def get_user_by_id(user_id: str) -> Optional[User]: session = db_session.create_session() user = session.query(User).filter(User.id == user_id).first() return user
def create_user_task(user_id, desc) -> bool: session = db_session.create_session() user = session.query(User).filter(User.id == user_id).first() new_task = Task(desc=desc) user.tasks.append(new_task) session.commit() return True
def does_email_exist(email: str) -> bool: session = db_session.create_session() user = session.query(User).filter(User.email == email).first() if user: return True else: return False
def login_user(email: str, password: str) -> Optional[User]: session = db_session.create_session() user = session.query(User).filter(User.email == email).first() if not user or not crypto.verify(password, user.hashed_password): return None return user
def add_user(name: str, email: str, password: str) -> Optional[User]: user = User() user.name = name user.email = email user.hashed_password = hash_text(password) session = db_session.create_session() session.add(user) session.commit() return user
def get_user_task_count(user_id) -> int: session = db_session.create_session() return len(session.query(User).filter(User.id == user_id).first().tasks)
def get_user_tasks(user_id) -> [Task]: session = db_session.create_session() return session.query(User).filter(User.id == user_id).first().tasks