예제 #1
0
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()
예제 #2
0
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
예제 #3
0
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
예제 #4
0
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
예제 #5
0
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
예제 #6
0
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
예제 #7
0
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)
예제 #8
0
def get_user_tasks(user_id) -> [Task]:
    session = db_session.create_session()
    return session.query(User).filter(User.id == user_id).first().tasks