Show number of participants
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -747,6 +747,28 @@ defmodule Mobilizon.Events do
|
||||
|> paginate(page, limit)
|
||||
end
|
||||
|
||||
def count_approved_participants(id) do
|
||||
query =
|
||||
from(
|
||||
p in Participant,
|
||||
where: p.role != ^:not_approved,
|
||||
where: p.event_id == ^id
|
||||
)
|
||||
|
||||
Repo.aggregate(query, :count, :id)
|
||||
end
|
||||
|
||||
def count_unapproved_participants(id) do
|
||||
query =
|
||||
from(
|
||||
p in Participant,
|
||||
where: p.role == ^:not_approved,
|
||||
where: p.event_id == ^id
|
||||
)
|
||||
|
||||
Repo.aggregate(query, :count, :id)
|
||||
end
|
||||
|
||||
@doc """
|
||||
Returns the list of participations for an actor.
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
alias Mobilizon.Addresses
|
||||
alias Mobilizon.Addresses.Address
|
||||
alias Mobilizon.Events
|
||||
alias Mobilizon.Events.{Event, Participant}
|
||||
alias Mobilizon.Events.{Event, Participant, EventOptions}
|
||||
alias Mobilizon.Media.Picture
|
||||
alias Mobilizon.Users.User
|
||||
alias Mobilizon.Actors
|
||||
@@ -51,6 +51,14 @@ defmodule MobilizonWeb.Resolvers.Event do
|
||||
{:ok, Mobilizon.Events.list_participants_for_event(uuid, 1, 10)}
|
||||
end
|
||||
|
||||
def stats_participants_for_event(%Event{id: id}, _args, _resolution) do
|
||||
{:ok,
|
||||
%{
|
||||
approved: Mobilizon.Events.count_approved_participants(id),
|
||||
unapproved: Mobilizon.Events.count_unapproved_participants(id)
|
||||
}}
|
||||
end
|
||||
|
||||
@doc """
|
||||
List related events
|
||||
"""
|
||||
|
||||
@@ -54,6 +54,8 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||
|
||||
field(:category, :string, description: "The event's category")
|
||||
|
||||
field(:participant_stats, :participant_stats, resolve: &Event.stats_participants_for_event/3)
|
||||
|
||||
field(:participants, list_of(:participant),
|
||||
resolve: &Event.list_participants_for_event/3,
|
||||
description: "The event's participants"
|
||||
@@ -92,6 +94,11 @@ defmodule MobilizonWeb.Schema.EventType do
|
||||
value(:cancelled, description: "The event is cancelled")
|
||||
end
|
||||
|
||||
object :participant_stats do
|
||||
field(:approved, :integer, description: "The number of approved participants")
|
||||
field(:unapproved, :integer, description: "The number of unapproved participants")
|
||||
end
|
||||
|
||||
object :event_offer do
|
||||
field(:price, :float, description: "The price amount for this offer")
|
||||
field(:price_currency, :string, description: "The currency for this price offer")
|
||||
|
||||
Reference in New Issue
Block a user