Fix filter validation
This commit is contained in:
parent
cf9784b770
commit
03ea9d0235
@ -27,17 +27,16 @@ async def retrieve_flights(user: str = "", sort: str = "date", order: int = -1,
|
||||
:param filter_val: Value to filter field by
|
||||
:return: List of flights
|
||||
"""
|
||||
if filter not in FlightDisplaySchema.__annotations__.keys():
|
||||
raise HTTPException(400, f"Invalid filter field: {filter}")
|
||||
|
||||
filter_options = {}
|
||||
if user != "":
|
||||
filter_options["user"] = ObjectId(user)
|
||||
if filter != "":
|
||||
if filter != "" and filter_val != "":
|
||||
fs_keys = list(FlightCreateSchema.__annotations__.keys())
|
||||
fs_keys.extend(list(FlightDisplaySchema.__annotations__.keys()))
|
||||
if filter not in fs_keys:
|
||||
raise HTTPException(400, f"Invalid filter field: {filter}")
|
||||
filter_options[filter] = filter_val
|
||||
|
||||
print(filter_options)
|
||||
|
||||
flights = []
|
||||
async for flight in flight_collection.find(filter_options).sort({sort: order}):
|
||||
flights.append(FlightConciseSchema(**flight_display_helper(flight)))
|
||||
|
Loading…
x
Reference in New Issue
Block a user