From 52163a84ee98a47c72b188cc2d72d2b9043bb8a1 Mon Sep 17 00:00:00 2001 From: pphetra Date: Thu, 25 Aug 2022 16:00:27 +0700 Subject: [PATCH] implement myIncidentReports query. --- reports/schema/query.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/reports/schema/query.py b/reports/schema/query.py index 8cbcdbc..d7f7209 100644 --- a/reports/schema/query.py +++ b/reports/schema/query.py @@ -34,6 +34,7 @@ class Query(graphene.ObjectType): category = graphene.Field(CategoryType, id=graphene.ID(required=True)) report_type = graphene.Field(ReportTypeType, id=graphene.ID(required=True)) incident_reports = DjangoPaginationConnectionField(IncidentReportType) + my_incident_reports = DjangoPaginationConnectionField(IncidentReportType) incident_report = graphene.Field(IncidentReportType, id=graphene.ID(required=True)) followup_report = graphene.Field(FollowupReportType, id=graphene.ID(required=True)) reporter_notification = graphene.Field( @@ -117,3 +118,13 @@ def resolve_incident_reports(root, info, **kwargs): query = query.filter(relevant_authorities__in=child_authorities) return query + + @staticmethod + @login_required + def resolve_my_incident_reports(root, info, **kwargs): + user = info.context.user + return ( + IncidentReport.objects.filter(reported_by=user) + .order_by("-created_at") + .prefetch_related("images", "reported_by", "report_type") + )