31 lines
756 B
Elixir
31 lines
756 B
Elixir
defmodule ToweropsWeb.GraphQL.Resolvers.Activity do
|
|
@moduledoc "GraphQL resolvers for activity feed."
|
|
|
|
alias Towerops.ActivityFeed
|
|
|
|
def list(_parent, args, %{context: %{organization_id: org_id}}) do
|
|
opts =
|
|
[limit: Map.get(args, :limit, 50)]
|
|
|> maybe_add_type(args[:type])
|
|
|
|
items = ActivityFeed.list_org_activity(org_id, opts)
|
|
{:ok, items}
|
|
end
|
|
|
|
def list(_parent, _args, _resolution), do: {:error, "Authentication required"}
|
|
|
|
defp maybe_add_type(opts, nil), do: opts
|
|
|
|
defp maybe_add_type(opts, type) do
|
|
case safe_to_atom(type) do
|
|
nil -> opts
|
|
atom -> Keyword.put(opts, :types, [atom])
|
|
end
|
|
end
|
|
|
|
defp safe_to_atom(str) do
|
|
String.to_existing_atom(str)
|
|
rescue
|
|
ArgumentError -> nil
|
|
end
|
|
end
|