Skip to content

Commit

Permalink
filter users to make sure we do not match nonexistent users
Browse files Browse the repository at this point in the history
  • Loading branch information
snophey committed Oct 29, 2023
1 parent 8d7b9e9 commit fd68f1f
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion functions/main.py
Expand Up @@ -5,6 +5,7 @@
from firebase_functions import https_fn
from firebase_admin import initialize_app
from firebase_admin import firestore
from firebase_admin import auth
from datetime import date
from data import User, Match
from notification import notify_user_about_match, POSTMARK_API_KEY
Expand All @@ -14,12 +15,20 @@

default_app = initialize_app()

def user_exists(uid: str):
try:
auth.get_user(uid)
return True
except:
print("User with ID " + uid + " does not exist")
return False

def get_all_users():
db = firestore.client()
docs = (
db.collection("users")
.stream())
return [ User(doc.id, doc.to_dict()) for doc in docs ]
return [ User(doc.id, doc.to_dict()) for doc in docs if user_exists(doc.id) ]

def match_users(users: list[User]):
# this is the entrypoint for your matching code
Expand Down

0 comments on commit fd68f1f

Please sign in to comment.