Add a default `last_topic` to the PrivateUserNode

This commit is contained in:
Ramon Wenger 2023-08-31 17:20:39 +02:00
parent c4b652c064
commit 6fff84127c
1 changed files with 8 additions and 2 deletions

View File

@ -11,6 +11,7 @@ from graphql_relay import to_global_id
from api.types import FailureNode from api.types import FailureNode
from books.models import Module from books.models import Module
from books.models.topic import Topic
from books.schema.nodes import ModuleLevelNode from books.schema.nodes import ModuleLevelNode
from books.schema.queries import ModuleNode from books.schema.queries import ModuleNode
from users.models import SchoolClass, SchoolClassMember, Team, User from users.models import SchoolClass, SchoolClassMember, Team, User
@ -104,7 +105,7 @@ class PrivateUserNode(DjangoObjectType):
"onboarding_visited", "onboarding_visited",
"team", "team",
"read_only", "read_only",
"last_module_level" "last_module_level",
] ]
interfaces = (relay.Node,) interfaces = (relay.Node,)
@ -142,6 +143,12 @@ class PrivateUserNode(DjangoObjectType):
def resolve_is_teacher(root: User, info): def resolve_is_teacher(root: User, info):
return root.is_teacher() return root.is_teacher()
@staticmethod
def resolve_last_topic(root: User, info):
if root.last_topic is not None:
return root.last_topic
return Topic.objects.first()
@staticmethod @staticmethod
def resolve_school_classes(root: User, info): def resolve_school_classes(root: User, info):
if root.selected_class is None: # then we don't have any class to return if root.selected_class is None: # then we don't have any class to return
@ -164,7 +171,6 @@ class PrivateUserNode(DjangoObjectType):
return self.team return self.team
class ClassMemberNode(ObjectType): class ClassMemberNode(ObjectType):
""" """
We need to build this ourselves, because we want the active property on the node, because providing it on the We need to build this ourselves, because we want the active property on the node, because providing it on the