2018-12-14 17:41:55 +01:00
|
|
|
defmodule MobilizonWeb.Resolvers.Comment do
|
2019-01-03 14:59:59 +01:00
|
|
|
@moduledoc """
|
2019-09-22 16:26:23 +02:00
|
|
|
Handles the comment-related GraphQL calls.
|
2019-01-03 14:59:59 +01:00
|
|
|
"""
|
2019-09-13 01:35:03 +02:00
|
|
|
|
2019-09-22 09:24:18 +02:00
|
|
|
alias Mobilizon.Events.Comment
|
2019-09-22 16:26:23 +02:00
|
|
|
alias Mobilizon.Users.User
|
2019-10-25 17:43:37 +02:00
|
|
|
alias Mobilizon.Actors.Actor
|
2019-09-22 16:26:23 +02:00
|
|
|
|
2018-12-14 17:41:55 +01:00
|
|
|
alias MobilizonWeb.API.Comments
|
|
|
|
|
2019-09-13 01:35:03 +02:00
|
|
|
require Logger
|
|
|
|
|
2019-10-25 17:43:37 +02:00
|
|
|
def create_comment(_parent, %{text: text, actor_id: actor_id}, %{
|
|
|
|
context: %{current_user: %User{} = user}
|
2018-12-14 17:41:55 +01:00
|
|
|
}) do
|
2019-10-25 17:43:37 +02:00
|
|
|
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
|
2019-07-30 10:35:29 +02:00
|
|
|
{:ok, comment}
|
2018-12-14 17:41:55 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create_comment(_parent, _args, %{}) do
|
|
|
|
{:error, "You are not allowed to create a comment if not connected"}
|
|
|
|
end
|
|
|
|
end
|