diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py index aae1b70603f0b0e5c738d81467d31f3844f13a86..a5709a12a6301ebf68dfc5e7b11593548175d0ff 100644 --- a/aleksis/apps/alsijil/schema/__init__.py +++ b/aleksis/apps/alsijil/schema/__init__.py @@ -37,6 +37,13 @@ class Query(graphene.ObjectType): groups_by_person = FilterOrderList(GroupType, person=graphene.ID()) courses_of_person = FilterOrderList(CourseType, person=graphene.ID()) + lesson_events_for_absences = FilterOrderList( + PersonAbsencesType??, + persons=graphene.List(graphene.ID, required=True), + start=graphene.Date(required=True), + end=graphene.Date(required=True), + ) + def resolve_documentations_by_course_id(root, info, course_id, **kwargs): documentations = Documentation.objects.filter( Q(course__pk=course_id) | Q(amends__course__pk=course_id) @@ -116,6 +123,34 @@ class Query(graphene.ObjectType): | Q(groups__parent_groups__owners=person) ) + def lesson_events_for_absences( + root, + info, + persons, + start, + end, + **kwargs, + ): + # Do date like resolve_documentations_for_coursebook? + + # Get all lesson events for person + # Make this reusable for mutation + # Pack into (id fullname lesson (start end course subject ...)) + + event_params = { + "" + } + + events = LessonEvent.get_single_events( + start, + end, + request??, + event_params, + with_reference_object=True, + ) + + return class Mutation(graphene.ObjectType): create_or_update_documentations = DocumentationBatchCreateOrUpdateMutation.Field() + create_absences = AbsencesBatchCreateMutation.Field() diff --git a/aleksis/apps/alsijil/schema/absences.py b/aleksis/apps/alsijil/schema/absences.py new file mode 100644 index 0000000000000000000000000000000000000000..f7c27a92bd80afcc2cfedbb52ce6c3c0c9b458fe --- /dev/null +++ b/aleksis/apps/alsijil/schema/absences.py @@ -0,0 +1,25 @@ +import graphene + +class AbsencesBatchCreateMutation(graphene.Mutation): + class Arguments: + persons = graphene.List(graphene.ID) + start = graphene.Date(), + end = graphene.Date(), + comment = graphene.String(), + reason = graphene.ID() + + ok = graphene.Boolean() + + @classmethod + def mutate(cls, root, info, input): # noqa + # Get all lesson events for person (share with query) + # Look up documentations for lesson events + # (share with models.py Documentation get_for_coursebook; + # has lesson event lookup as well & returns real & fake documentations + # => extract & reuse the documentation lookup) + # Create a ParticipationStatus for each documentation + # If there are any LessonEvents without a documentation + # create a Kolego Absence for the whole duration + # Return ok=True if everything went well. + + return AbsencesBatchCreateMutation(ok=BOOL)