@@ -20,29 +20,61 @@ def getUserQuery():
2020 "LEFT JOIN Sponsors as s ON u.sponsor_id = s.sponsor_id "
2121
2222
23- def getUsers (status = None , is_virtual = None ) -> list :
23+ def getUsers (applicationStatusFilterList : List [str ] = None , is_virtual = None , firstName = None , lastName = None , userId = None ,
24+ email = None , applicationId = None ) -> list :
2425 """
2526 Get a filtered list of all users in json/dictionary format
26- :param status: string matching user application status
27+ :param applicationId:
28+ :param email:
29+ :param userId:
30+ :param lastName:
31+ :param firstName:
32+ :param applicationStatusFilterList: list of statuses to match
2733 :param is_virtual: boolean for if you want all virtual/in person users
28- :return: list of dictionaries with user information
34+ :return: list of dictionaries with user information, None if error
2935 """
30-
3136 sql = getUserQuery ()
37+ firstWhereClause = True
3238 args = ()
33- if status is not None :
34- sql += "WHERE app.status = %s"
35- args = args + (status ,)
36- if is_virtual is not None :
37- sql += "AND WHERE app.is_virtual = %s"
38- args = args + (is_virtual ,)
39- elif is_virtual is not None :
40- sql += "WHERE app.is_virtual = %s"
39+
40+ if applicationStatusFilterList is not None :
41+ sql += f" WHERE app.status in ({ ',' .join (['%s' ] * len (applicationStatusFilterList ))} ) "
42+ for status in applicationStatusFilterList :
43+ args = args + (status ,)
44+ if is_virtual is not None :
45+ sql += getOptionalAnd (firstWhereClause ) + " WHERE app.is_virtual = %s "
4146 args = args + (is_virtual ,)
47+ if firstName is not None :
48+ sql += getOptionalAnd (firstWhereClause ) + " WHERE u.first_name = %s "
49+ args = args + (firstName ,)
50+ if lastName is not None :
51+ sql += getOptionalAnd (firstWhereClause ) + " WHERE u.last_name = %s "
52+ args = args + (lastName ,)
53+ if userId is not None :
54+ sql += getOptionalAnd (firstWhereClause ) + " WHERE u.user_id = %s "
55+ args = args + (userId ,)
56+ if email is not None :
57+ sql += getOptionalAnd (firstWhereClause ) + " WHERE u.email = %s "
58+ args = args + (email ,)
59+ if applicationId is not None :
60+ sql += getOptionalAnd (firstWhereClause ) + " WHERE app.application_id = %s "
61+ args = args + (applicationId ,)
4262
4363 return exec_get_all (sql , args )
4464
4565
66+ def getOptionalAnd (isFirstWhereClause ) -> str :
67+ """
68+ Helper function, returns "AND " if clause isn't the first and empty string if it is
69+ :param isFirstWhereClause:
70+ :return:
71+ """
72+ if isFirstWhereClause :
73+ return ""
74+ else :
75+ return " AND "
76+
77+
4678def getUserByAuthID (auth_id ) -> dict :
4779 """
4880 wrapper for getting user using auth0 id
@@ -94,7 +126,7 @@ def getUserById(auth_id=None, user_id=None) -> dict:
94126 if auth_id is not None :
95127 sql += "WHERE u.auth0_id = %s"
96128 args = args + (auth_id ,)
97- if user_id is not None :
129+ elif user_id is not None :
98130 sql += "WHERE u.user_id = %s"
99131 args = args + (user_id ,)
100132
@@ -121,4 +153,3 @@ def getUserEmailsWithFilter(applicationStatusFilterList: List[str]):
121153 if len (u ['email' ]) > 1 :
122154 emailList .append (u ['email' ])
123155 return emailList
124-
0 commit comments