diff --git a/lib/radiator/outline.ex b/lib/radiator/outline.ex index d0f45cec..a1a7bb0e 100644 --- a/lib/radiator/outline.ex +++ b/lib/radiator/outline.ex @@ -197,10 +197,7 @@ defmodule Radiator.Outline do ## Examples iex> remove_node(node) - {:ok, %Node{}} - - iex> remove_node(node) - {:error, %Ecto.Changeset{}} + { %NodeRepoResult{} } """ def remove_node(%Node{} = node) do diff --git a/lib/radiator/outline/event_consumer.ex b/lib/radiator/outline/event_consumer.ex index aeded465..57699326 100644 --- a/lib/radiator/outline/event_consumer.ex +++ b/lib/radiator/outline/event_consumer.ex @@ -70,14 +70,23 @@ defmodule Radiator.Outline.EventConsumer do defp process_command(%DeleteNodeCommand{node_id: node_id} = command) do case NodeRepository.get_node(node_id) do - nil -> Logger.error("Could not remove node. Node not found.") - node -> Outline.remove_node(node) + nil -> + Logger.error("Could not remove node. Node not found.") + + node -> + result = Outline.remove_node(node) + + %NodeDeletedEvent{ + node_id: node_id, + uuid: command.event_id, + user_id: command.user_id, + children: result.children, + next_id: result.next_id + } + |> EventStore.persist_event() + |> Dispatch.broadcast() end - %NodeDeletedEvent{node_id: node_id, uuid: command.event_id, user_id: command.user_id} - |> EventStore.persist_event() - |> Dispatch.broadcast() - :ok end