Example #1
0
def check_request(id):

    current_user = User.get_by_id(get_jwt_identity())
    recipient = User.get_by_id(id)

    check = FriendRequest.select().where(
        FriendRequest.sender_id == current_user.id,
        FriendRequest.recipient_id == recipient.id)
    check2 = FriendRequest.select().where(
        FriendRequest.sender_id == recipient.id,
        FriendRequest.recipient_id == current_user.id)

    if check or check2:
        return jsonify({"exist": True})
    else:
        return jsonify({"exist": False})
Example #2
0
def show_request():
    current_user = User.get_by_id(get_jwt_identity())

    friend_request = FriendRequest.select().where(
        FriendRequest.recipient_id == current_user.id)

    results = []
    for f in friend_request:
        sender = User.get_by_id(f.sender_id)
        data = {"id": sender.id, "name": sender.username}
        results.append(data)

    return jsonify({"data": results})