Add mutation to update chosen profile
This commit is contained in:
parent
bb1afd7205
commit
eaeac374c1
|
|
@ -1,7 +1,9 @@
|
|||
import graphene
|
||||
import structlog
|
||||
from graphene import relay
|
||||
from rest_framework.exceptions import PermissionDenied
|
||||
|
||||
from vbv_lernwelt.course.models import CourseSessionUser
|
||||
from vbv_lernwelt.course_session.graphql.types import (
|
||||
CourseSessionAttendanceCourseObjectType,
|
||||
)
|
||||
|
|
@ -11,10 +13,33 @@ from vbv_lernwelt.course_session.services.attendance import (
|
|||
update_attendance_list,
|
||||
)
|
||||
from vbv_lernwelt.iam.permissions import has_course_access
|
||||
from vbv_lernwelt.learnpath.models import CourseProfile
|
||||
|
||||
logger = structlog.get_logger(__name__)
|
||||
|
||||
|
||||
class UpdateCourseProfileSuccess(graphene.ObjectType):
|
||||
message = graphene.String()
|
||||
|
||||
def resolve_message(cls, instance, **kwargs):
|
||||
return "Update successful"
|
||||
|
||||
|
||||
class UpdateCourseProfileError(graphene.ObjectType):
|
||||
message = graphene.String()
|
||||
|
||||
|
||||
class UpdateCourseProfileResult(graphene.Union):
|
||||
class Meta:
|
||||
types = (UpdateCourseProfileSuccess, UpdateCourseProfileError)
|
||||
|
||||
@classmethod
|
||||
def resolve_type(cls, instance, info):
|
||||
if type(instance).__name__ == "UpdateCourseProfileError":
|
||||
return UpdateCourseProfileError
|
||||
return UpdateCourseProfileSuccess
|
||||
|
||||
|
||||
class AttendanceUserInputType(graphene.InputObjectType):
|
||||
user_id = graphene.UUID(required=True)
|
||||
status = graphene.Field(
|
||||
|
|
@ -57,5 +82,37 @@ class AttendanceCourseUserMutation(graphene.Mutation):
|
|||
)
|
||||
|
||||
|
||||
class CourseSessionProfileMutation(relay.ClientIDMutation):
|
||||
class Input:
|
||||
course_profile = graphene.String(required=True)
|
||||
course_slug = graphene.String(required=True)
|
||||
|
||||
result = UpdateCourseProfileResult()
|
||||
|
||||
@classmethod
|
||||
def mutate_and_get_payload(cls, root, info, **input):
|
||||
course_profile = input.get("course_profile")
|
||||
course_slug = input.get("course_slug")
|
||||
user = info.context.user
|
||||
try:
|
||||
profile = CourseProfile.objects.get(code=course_profile)
|
||||
|
||||
# csu = user.coursesessionuser_set.first()
|
||||
csu = CourseSessionUser.objects.get(
|
||||
course_session__course__slug=course_slug, user=user
|
||||
)
|
||||
csu.chosen_profile = profile
|
||||
csu.save()
|
||||
print(user)
|
||||
return cls(result=True)
|
||||
except CourseProfile.DoesNotExist:
|
||||
return cls(result=UpdateCourseProfileError("Course Profile does not exist"))
|
||||
except CourseSessionUser.DoesNotExist:
|
||||
return cls(
|
||||
result=UpdateCourseProfileError("Course Session User does not exist")
|
||||
)
|
||||
|
||||
|
||||
class CourseSessionMutation:
|
||||
update_course_session_attendance_course_users = AttendanceCourseUserMutation.Field()
|
||||
update_course_session_profile = CourseSessionProfileMutation.Field()
|
||||
|
|
|
|||
Loading…
Reference in New Issue