Fix event stats participants / going incoherent

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2020-06-18 16:24:00 +02:00
parent fe14d2ed25
commit e030eab93d
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
3 changed files with 27 additions and 18 deletions

View File

@ -63,11 +63,11 @@
$tc(
"{available}/{capacity} available places",
participation.event.options.maximumAttendeeCapacity -
(participation.event.participantStats.going - 1),
participation.event.participantStats.participant,
{
available:
participation.event.options.maximumAttendeeCapacity -
(participation.event.participantStats.going - 1),
participation.event.participantStats.participant,
capacity: participation.event.options.maximumAttendeeCapacity,
}
)

View File

@ -174,11 +174,11 @@
$tc(
"{available}/{capacity} available places",
event.options.maximumAttendeeCapacity -
(event.participantStats.going - 1),
event.participantStats.participant,
{
available:
event.options.maximumAttendeeCapacity -
(event.participantStats.going - 1),
event.participantStats.participant,
capacity: event.options.maximumAttendeeCapacity,
}
)
@ -186,8 +186,8 @@
</span>
<span v-else>
{{
$tc("No one is going to this event", event.participantStats.going - 1, {
going: event.participantStats.going - 1,
$tc("No one is going to this event", event.participantStats.participant, {
going: event.participantStats.participant,
})
}}
</span>
@ -197,10 +197,12 @@
{{
$tc(
"{available}/{capacity} available places",
event.options.maximumAttendeeCapacity - event.participantStats.going,
event.options.maximumAttendeeCapacity -
event.participantStats.participant,
{
available:
event.options.maximumAttendeeCapacity - event.participantStats.going,
event.options.maximumAttendeeCapacity -
event.participantStats.participant,
capacity: event.options.maximumAttendeeCapacity,
}
)
@ -208,8 +210,8 @@
</span>
<span v-else>
{{
$tc("No one is going to this event", event.participantStats.going, {
going: event.participantStats.going,
$tc("No one is going to this event", event.participantStats.participant, {
going: event.participantStats.participant,
})
}}
</span>

View File

@ -107,24 +107,31 @@ defmodule Mobilizon.GraphQL.Resolvers.Event do
{:ok, %{total: 0, elements: []}}
end
def stats_participants_going(%EventParticipantStats{} = stats, _args, _resolution) do
{:ok, stats.participant + stats.moderator + stats.administrator + stats.creator}
end
def stats_participants(
%Event{participant_stats: %EventParticipantStats{} = stats, id: event_id} = _event,
_args,
%{context: %{current_user: %User{id: user_id} = _user}} = _resolution
) do
going = stats.participant + stats.moderator + stats.administrator + stats.creator
if Events.is_user_moderator_for_event?(user_id, event_id) do
{:ok, Map.put(stats, :going, going)}
{:ok,
Map.put(
stats,
:going,
stats.participant + stats.moderator + stats.administrator + stats.creator
)}
else
{:ok, %{going: going}}
{:ok, %{participant: stats.participant}}
end
end
def stats_participants(
%Event{participant_stats: %EventParticipantStats{participant: participant}},
_args,
_resolution
) do
{:ok, %EventParticipantStats{participant: participant}}
end
def stats_participants(_event, _args, _resolution) do
{:ok, %EventParticipantStats{}}
end