Fixed ObjectId issue

This commit is contained in:
nsde 2023-09-14 20:43:24 +02:00
parent 8b325d6b81
commit e06073fba5
2 changed files with 7 additions and 0 deletions

View file

@ -50,6 +50,9 @@ async def get_users(discord_id: int, incoming_request: fastapi.Request):
if not user: if not user:
return await errors.error(404, 'Discord user not found in the API database.', 'Check the `discord_id` parameter.') return await errors.error(404, 'Discord user not found in the API database.', 'Check the `discord_id` parameter.')
# turn the ObjectId into a string
user['_id'] = str(user['_id'])
return user return user
async def new_user_webhook(user: dict) -> None: async def new_user_webhook(user: dict) -> None:
@ -90,6 +93,8 @@ async def create_user(incoming_request: fastapi.Request):
user = await manager.create(discord_id) user = await manager.create(discord_id)
await new_user_webhook(user) await new_user_webhook(user)
user['_id'] = str(user['_id'])
return user return user
@router.put('/users') @router.put('/users')

View file

@ -5,7 +5,9 @@ import pydantic
from rich import print from rich import print
from dotenv import load_dotenv from dotenv import load_dotenv
from bson.objectid import ObjectId from bson.objectid import ObjectId
from slowapi.errors import RateLimitExceeded from slowapi.errors import RateLimitExceeded
from slowapi.middleware import SlowAPIMiddleware from slowapi.middleware import SlowAPIMiddleware
from fastapi.middleware.cors import CORSMiddleware from fastapi.middleware.cors import CORSMiddleware