diff options
Diffstat (limited to 'backend/routes/forms/index.py')
-rw-r--r-- | backend/routes/forms/index.py | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/backend/routes/forms/index.py b/backend/routes/forms/index.py index 183d5cc..f1df210 100644 --- a/backend/routes/forms/index.py +++ b/backend/routes/forms/index.py @@ -1,10 +1,12 @@ """ Return a list of all forms to authenticated users. """ +from starlette.authentication import requires from starlette.requests import Request from starlette.responses import JSONResponse from backend.route import Route +from backend.models import Form class FormsList(Route): @@ -15,11 +17,16 @@ class FormsList(Route): name = "forms_list" path = "/" + @requires(["authenticated", "admin"]) async def get(self, request: Request) -> JSONResponse: forms = [] + cursor = request.state.db.forms.find() - for form in request.state.db.forms.find(): - forms.append(form) + for form in await cursor.to_list(None): + forms.append(Form(**form)) # For converting _id to id + + # Covert them back to dictionaries + forms = [form.dict() for form in forms] return JSONResponse( forms |