diff --git a/src/api/categories.py b/src/api/categories.py index da5c142..549c38d 100644 --- a/src/api/categories.py +++ b/src/api/categories.py @@ -10,7 +10,7 @@ from src.api.auth.dependencies import LoggedInDep from src.db.models.category import Category from src.db.models.event import Event from src.db.models.user import User -from src.utils.db import MissingIdError, expr, update_document +from src.utils.db import MissingIdError, UnfetchedLinkError, expr, update_document from src.utils.logging import get_logger from .auth import CurrentUserDep @@ -42,6 +42,7 @@ class _BaseCategoryData(BaseModel): class CategoryData(_BaseCategoryData): """Data about a category sent to the user.""" + id: PydanticObjectId owner_user_id: PydanticObjectId created_at: datetime @@ -51,10 +52,16 @@ class CategoryData(_BaseCategoryData): if category.id is None: raise MissingIdError(category) + if isinstance(category.user, Link): + raise UnfetchedLinkError(category.user) + if category.user.id is None: + raise MissingIdError(category.user) + return cls( + id=category.id, name=category.name, color=Color(category.color), - owner_user_id=category.id, + owner_user_id=category.user.id, created_at=category.created_at, )