Skip to content

Commit

Permalink
implement myIncidentReports query.
Browse files Browse the repository at this point in the history
  • Loading branch information
pphetra committed Aug 25, 2022
1 parent 754585d commit 52163a8
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions reports/schema/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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")
)

0 comments on commit 52163a8

Please sign in to comment.