Add pagination to moderation logs
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
@@ -27,7 +27,8 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||
%{context: %{current_user: %User{role: role}}}
|
||||
)
|
||||
when is_moderator(role) do
|
||||
with action_logs <- Mobilizon.Admin.list_action_logs(page, limit) do
|
||||
with %Page{elements: action_logs, total: total} <-
|
||||
Mobilizon.Admin.list_action_logs(page, limit) do
|
||||
action_logs =
|
||||
action_logs
|
||||
|> Enum.map(fn %ActionLog{
|
||||
@@ -44,7 +45,7 @@ defmodule Mobilizon.GraphQL.Resolvers.Admin do
|
||||
end)
|
||||
|> Enum.filter(& &1)
|
||||
|
||||
{:ok, action_logs}
|
||||
{:ok, %Page{elements: action_logs, total: total}}
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -22,6 +22,14 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
|
||||
field(:inserted_at, :datetime, description: "The time when the action was performed")
|
||||
end
|
||||
|
||||
@desc """
|
||||
A paginated list of action logs
|
||||
"""
|
||||
object :paginated_action_log_list do
|
||||
field(:elements, list_of(:action_log), description: "A list of action logs")
|
||||
field(:total, :integer, description: "The total number of action logs in the list")
|
||||
end
|
||||
|
||||
@desc """
|
||||
The different types of action log actions
|
||||
"""
|
||||
@@ -147,7 +155,7 @@ defmodule Mobilizon.GraphQL.Schema.AdminType do
|
||||
|
||||
object :admin_queries do
|
||||
@desc "Get the list of action logs"
|
||||
field :action_logs, type: list_of(:action_log) do
|
||||
field :action_logs, type: :paginated_action_log_list do
|
||||
arg(:page, :integer, default_value: 1)
|
||||
arg(:limit, :integer, default_value: 10)
|
||||
resolve(&Admin.list_action_logs/3)
|
||||
|
||||
@@ -36,11 +36,10 @@ defmodule Mobilizon.Admin do
|
||||
@doc """
|
||||
Returns the list of action logs.
|
||||
"""
|
||||
@spec list_action_logs(integer | nil, integer | nil) :: [ActionLog.t()]
|
||||
@spec list_action_logs(integer | nil, integer | nil) :: Page.t()
|
||||
def list_action_logs(page \\ nil, limit \\ nil) do
|
||||
list_action_logs_query()
|
||||
|> Page.paginate(page, limit)
|
||||
|> Repo.all()
|
||||
|> Page.build_page(page, limit)
|
||||
end
|
||||
|
||||
@doc """
|
||||
|
||||
Reference in New Issue
Block a user