From d50cc2f91a11116492b7f19daf7b87adc7ae5b83 Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Fri, 17 May 2024 20:18:26 +0200
Subject: [PATCH] Make school term query arg optional and adapt to core

person & schoolTerm are both objects now in personOverviewCardMixin.
---
 .../statistics/StatisticsForPersonCard.vue           | 10 ++++++++++
 .../coursebook/statistics/statistics.graphql         |  4 ++--
 aleksis/apps/alsijil/schema/__init__.py              | 12 ++++++------
 3 files changed, 18 insertions(+), 8 deletions(-)

diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
index a5498363b..7d13ae630 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
@@ -52,6 +52,16 @@ export default {
   apollo: {
     statistics: {
       query: statisticsByPerson,
+      variables() {
+        const term = this.schoolTerm
+              ? { term: this.schoolTerm.id }
+              : {};
+
+        return {
+          person: this.person.id,
+          ...term,
+        };
+      },
     },
   },
 };
diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/statistics.graphql b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/statistics.graphql
index e9f1e5d52..c9aa8e1ed 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/statistics.graphql
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/statistics.graphql
@@ -28,7 +28,7 @@ fragment statistics on StatisticsByPersonType {
 
 query statisticsByPerson (
   $person: ID!
-  $term: ID!
+  $term: ID
 ) {
   statistics: statisticsByPerson(
     person: $person
@@ -40,7 +40,7 @@ query statisticsByPerson (
 
 query statisticsByGroup (
   $group: ID!
-  $term: ID!
+  $term: ID
 ) {
   statistics: statisticsByGroup(
     group: $group
diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py
index c49e6e91c..986256eba 100644
--- a/aleksis/apps/alsijil/schema/__init__.py
+++ b/aleksis/apps/alsijil/schema/__init__.py
@@ -51,13 +51,13 @@ class Query(graphene.ObjectType):
 
     statistics_by_person = graphene.Field(
         StatisticsByPersonType,
-        person=graphene.ID(),
-        term=graphene.ID(),
+        person=graphene.ID(required=True),
+        term=graphene.ID(required=False),
     )
     statistics_by_group = graphene.List(
         StatisticsByPersonType,
-        group=graphene.ID(),
-        term=graphene.ID(),
+        group=graphene.ID(required=True),
+        term=graphene.ID(required=False),
     )
 
     def resolve_documentations_by_course_id(root, info, course_id, **kwargs):
@@ -183,12 +183,12 @@ class Query(graphene.ObjectType):
         return lessons_for_person
 
     @staticmethod
-    def resolve_statistics_by_person(root, info, person, term):
+    def resolve_statistics_by_person(root, info, person, term=None):
         # TODO: Annotate person with necessary information for term.
         return Person.objects.get(id=person)
 
     @staticmethod
-    def resolve_statistics_by_group(root, info, group, term):
+    def resolve_statistics_by_group(root, info, group, term=None):
         # TODO: Annotate persons with necessary information for term.
         return Group.objects.get(id=group).members.all()
 
-- 
GitLab