mobilizon.chapril.org-mobil.../lib/mobilizon_web/resolvers/comment.ex

28 lines
755 B
Elixir
Raw Normal View History

defmodule MobilizonWeb.Resolvers.Comment do
@moduledoc """
2019-09-22 16:26:23 +02:00
Handles the comment-related GraphQL calls.
"""
2019-09-13 01:35:03 +02:00
alias Mobilizon.Events.Comment
2019-09-22 16:26:23 +02:00
alias Mobilizon.Users.User
alias Mobilizon.Actors.Actor
2019-09-22 16:26:23 +02:00
alias MobilizonWeb.API.Comments
2019-09-13 01:35:03 +02:00
require Logger
def create_comment(_parent, %{text: text, actor_id: actor_id}, %{
context: %{current_user: %User{} = user}
}) do
with {:is_owned, %Actor{} = _organizer_actor} <- User.owns_actor(user, actor_id),
{:ok, _, %Comment{} = comment} <-
Comments.create_comment(%{actor_id: actor_id, text: text}) do
{:ok, comment}
end
end
def create_comment(_parent, _args, %{}) do
{:error, "You are not allowed to create a comment if not connected"}
end
end