From 8dfd2d8b9a8f287e265f35948fa2e97ea481c933 Mon Sep 17 00:00:00 2001
From: Michael Bauer <michael-bauer@posteo.de>
Date: Wed, 15 May 2024 14:06:24 +0200
Subject: [PATCH] Fix statistics query

---
 .../statistics/StatisticsForPersonCard.vue    |  2 +-
 .../coursebook/statistics/statistics.graphql  | 22 +++++++++--------
 aleksis/apps/alsijil/schema/__init__.py       | 24 ++++++++++++-------
 3 files changed, 29 insertions(+), 19 deletions(-)

diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
index 17cf82321..a5498363b 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/StatisticsForPersonCard.vue
@@ -31,7 +31,7 @@ import StatisticsTardinessCard from "./StatisticsTardinessCard.vue";
 import StatisticsExtraMarksCard from "./StatisticsExtraMarksCard.vue";
 import StatisticsPersonalNotesList from "./StatisticsPersonalNotesList.vue";
 
-import statisticsByPerson from "./statistics.graphql";
+import { statisticsByPerson } from "./statistics.graphql";
 
 export default {
   name: "StatisticsForPersonCard",
diff --git a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/statistics.graphql b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/statistics.graphql
index 266702ea6..e9f1e5d52 100644
--- a/aleksis/apps/alsijil/frontend/components/coursebook/statistics/statistics.graphql
+++ b/aleksis/apps/alsijil/frontend/components/coursebook/statistics/statistics.graphql
@@ -8,7 +8,7 @@ fragment statistics on StatisticsByPersonType {
       shortName
       name
       colour
-      countAsAbsent
+      default
     }
   }
   tardinessSum
@@ -21,34 +21,36 @@ fragment statistics on StatisticsByPersonType {
       name
       colourFg
       colourBg
-      showInCourseBook
+      showInCoursebook
     }
   }
 }
 
 query statisticsByPerson (
-  $personId: ID!
-  $termId: ID!
+  $person: ID!
+  $term: ID!
 ) {
   statistics: statisticsByPerson(
-    $personId: ID!
-    $termId: ID!
+    person: $person
+    term: $term
   ) {
   ...statistics
+  }
 }
 
 query statisticsByGroup (
-  $groupId: ID!
-  $termId: ID!
+  $group: ID!
+  $term: ID!
 ) {
   statistics: statisticsByGroup(
-    $groupId: ID!
-    $termId: ID!
+    group: $group
+    term: $term
   ) {
   persons {
     id
     firstName
     lastName
     ...statistics
+    }
   }
 }
diff --git a/aleksis/apps/alsijil/schema/__init__.py b/aleksis/apps/alsijil/schema/__init__.py
index 0c7c299f0..c49e6e91c 100644
--- a/aleksis/apps/alsijil/schema/__init__.py
+++ b/aleksis/apps/alsijil/schema/__init__.py
@@ -49,8 +49,16 @@ class Query(graphene.ObjectType):
         end=graphene.Date(required=True),
     )
 
-    statistics_by_person = graphene.Field(StatisticsByPersonType)
-    statistics_by_group = graphene.List(StatisticsByPersonType)
+    statistics_by_person = graphene.Field(
+        StatisticsByPersonType,
+        person=graphene.ID(),
+        term=graphene.ID(),
+    )
+    statistics_by_group = graphene.List(
+        StatisticsByPersonType,
+        group=graphene.ID(),
+        term=graphene.ID(),
+    )
 
     def resolve_documentations_by_course_id(root, info, course_id, **kwargs):
         documentations = Documentation.objects.filter(
@@ -175,14 +183,14 @@ class Query(graphene.ObjectType):
         return lessons_for_person
 
     @staticmethod
-    def resolve_statistics_by_person(root, info, person_id, term_id):
-        # TODO: Annotate person with necessary information for term_id.
-        return Person.objects.get(id=person_id)
+    def resolve_statistics_by_person(root, info, person, term):
+        # TODO: Annotate person with necessary information for term.
+        return Person.objects.get(id=person)
 
     @staticmethod
-    def resolve_statistics_by_group(root, info, group_id, term_id):
-        # TODO: Annotate persons with necessary information for term_id.
-        return Group.objects.get(id=group_id).members.all()
+    def resolve_statistics_by_group(root, info, group, term):
+        # TODO: Annotate persons with necessary information for term.
+        return Group.objects.get(id=group).members.all()
 
 
 class Mutation(graphene.ObjectType):
-- 
GitLab