2020-01-26 20:34:25 +01:00
|
|
|
defmodule Mobilizon.GraphQL.Schema.Events.ParticipantType do
|
2019-01-14 17:48:08 +01:00
|
|
|
@moduledoc """
|
2019-09-22 16:26:23 +02:00
|
|
|
Schema representation for Participant.
|
2019-01-14 17:48:08 +01:00
|
|
|
"""
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2019-01-14 17:13:17 +01:00
|
|
|
use Absinthe.Schema.Notation
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2019-01-14 17:48:08 +01:00
|
|
|
import Absinthe.Resolution.Helpers, only: [dataloader: 1]
|
2019-09-22 16:26:23 +02:00
|
|
|
|
|
|
|
alias Mobilizon.{Actors, Events}
|
2019-12-20 13:04:34 +01:00
|
|
|
alias Mobilizon.GraphQL.Resolvers.Participant
|
2019-01-14 17:13:17 +01:00
|
|
|
|
|
|
|
@desc "Represents a participant to an event"
|
|
|
|
object :participant do
|
2019-09-20 18:22:03 +02:00
|
|
|
field(:id, :id, description: "The participation ID")
|
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
field(
|
|
|
|
:event,
|
|
|
|
:event,
|
2019-01-14 17:13:17 +01:00
|
|
|
resolve: dataloader(Events),
|
|
|
|
description: "The event which the actor participates in"
|
|
|
|
)
|
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
field(
|
|
|
|
:actor,
|
|
|
|
:actor,
|
|
|
|
resolve: dataloader(Actors),
|
|
|
|
description: "The actor that participates to the event"
|
|
|
|
)
|
|
|
|
|
2019-09-20 18:22:03 +02:00
|
|
|
field(:role, :participant_role_enum, description: "The role of this actor at this event")
|
2019-12-20 13:04:34 +01:00
|
|
|
|
|
|
|
field(:metadata, :participant_metadata,
|
|
|
|
description: "The metadata associated to this participant"
|
|
|
|
)
|
2020-03-05 19:32:34 +01:00
|
|
|
|
|
|
|
field(:inserted_at, :datetime, description: "The datetime this participant was created")
|
2019-12-20 13:04:34 +01:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc """
|
|
|
|
Metadata about a participant
|
|
|
|
"""
|
2019-12-20 13:04:34 +01:00
|
|
|
object :participant_metadata do
|
|
|
|
field(:cancellation_token, :string,
|
|
|
|
description: "The eventual token to leave an event when user is anonymous"
|
|
|
|
)
|
2020-03-05 19:32:34 +01:00
|
|
|
|
|
|
|
field(:message, :string, description: "The eventual message the participant left")
|
2020-06-09 10:07:30 +02:00
|
|
|
field(:locale, :string, description: "The participant's locale")
|
2020-03-05 19:32:34 +01:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc """
|
|
|
|
A paginated list of participants
|
|
|
|
"""
|
2020-03-05 19:32:34 +01:00
|
|
|
object :paginated_participant_list do
|
|
|
|
field(:elements, list_of(:participant), description: "A list of participants")
|
|
|
|
field(:total, :integer, description: "The total number of participants in the list")
|
2019-09-20 18:22:03 +02:00
|
|
|
end
|
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc """
|
|
|
|
The possible values for a participant role
|
|
|
|
"""
|
2019-09-20 18:22:03 +02:00
|
|
|
enum :participant_role_enum do
|
2020-11-19 17:06:28 +01:00
|
|
|
value(:not_approved, description: "The participant has not been approved")
|
|
|
|
value(:not_confirmed, description: "The participant has not confirmed their participation")
|
|
|
|
value(:participant, description: "The participant is a regular participant")
|
|
|
|
value(:moderator, description: "The participant is an event moderator")
|
|
|
|
value(:administrator, description: "The participant is an event administrator")
|
|
|
|
value(:creator, description: "The participant is an event creator")
|
|
|
|
value(:rejected, description: "The participant has been rejected from this event")
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|
2019-01-25 15:41:10 +01:00
|
|
|
|
2021-10-04 18:59:41 +02:00
|
|
|
enum :export_format_enum do
|
|
|
|
value(:csv, description: "CSV format")
|
|
|
|
value(:pdf, description: "PDF format")
|
|
|
|
value(:ods, description: "ODS format")
|
|
|
|
end
|
|
|
|
|
2019-02-01 15:38:35 +01:00
|
|
|
@desc "Represents a deleted participant"
|
|
|
|
object :deleted_participant do
|
2020-11-19 17:06:28 +01:00
|
|
|
field(:id, :id, description: "The participant ID")
|
|
|
|
field(:event, :deleted_object, description: "The participant's event")
|
|
|
|
field(:actor, :deleted_object, description: "The participant's actor")
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
object :participant_mutations do
|
|
|
|
@desc "Join an event"
|
|
|
|
field :join_event, :participant do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:event_id, non_null(:id), description: "The event ID that is joined")
|
|
|
|
arg(:actor_id, non_null(:id), description: "The actor ID for the participant")
|
|
|
|
arg(:email, :string, description: "The anonymous participant's email")
|
|
|
|
arg(:message, :string, description: "The anonymous participant's message")
|
|
|
|
arg(:locale, :string, description: "The anonymous participant's locale")
|
2021-10-13 12:55:49 +02:00
|
|
|
arg(:timezone, :string, description: "The anonymous participant's timezone")
|
2019-02-01 15:38:35 +01:00
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
resolve(&Participant.actor_join_event/3)
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Leave an event"
|
|
|
|
field :leave_event, :deleted_participant do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:event_id, non_null(:id), description: "The event ID the participant left")
|
|
|
|
arg(:actor_id, non_null(:id), description: "The actor ID for the participant")
|
|
|
|
arg(:token, :string, description: "The anonymous participant participation token")
|
2019-02-01 15:38:35 +01:00
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
resolve(&Participant.actor_leave_event/3)
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|
2019-09-20 18:22:03 +02:00
|
|
|
|
2020-11-19 17:06:28 +01:00
|
|
|
@desc "Update a participation"
|
2019-09-30 13:48:47 +02:00
|
|
|
field :update_participation, :participant do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:id, non_null(:id), description: "The participant ID")
|
|
|
|
arg(:role, non_null(:participant_role_enum), description: "The participant new role")
|
2019-09-20 18:22:03 +02:00
|
|
|
|
2019-12-20 13:04:34 +01:00
|
|
|
resolve(&Participant.update_participation/3)
|
|
|
|
end
|
|
|
|
|
|
|
|
@desc "Confirm a participation"
|
|
|
|
field :confirm_participation, :participant do
|
2020-11-19 17:06:28 +01:00
|
|
|
arg(:confirmation_token, non_null(:string), description: "The participation token")
|
2019-12-20 13:04:34 +01:00
|
|
|
resolve(&Participant.confirm_participation_from_token/3)
|
2019-09-20 18:22:03 +02:00
|
|
|
end
|
2021-10-04 18:59:41 +02:00
|
|
|
|
|
|
|
@desc "Export the event participants as a file"
|
|
|
|
field :export_event_participants, :string do
|
|
|
|
arg(:event_id, non_null(:id),
|
|
|
|
description: "The ID from the event for which to export participants"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:roles, list_of(:participant_role_enum),
|
|
|
|
default_value: [],
|
|
|
|
description: "The participant roles to include"
|
|
|
|
)
|
|
|
|
|
|
|
|
arg(:format, :export_format_enum, description: "The format in which to return the file")
|
|
|
|
resolve(&Participant.export_event_participants/3)
|
|
|
|
end
|
2019-02-01 15:38:35 +01:00
|
|
|
end
|
2019-01-14 17:13:17 +01:00
|
|
|
end
|