Created
September 11, 2018 10:24
-
-
Save rafaels88/f1a4128a5c277ea57a00ad3df3aa24e4 to your computer and use it in GitHub Desktop.
Quiqup.DispatchOrderStagePipeline
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule Quiqup.DispatchOrderStagePipeline do | |
def call(%{order_id: order_id}) do | |
with {:ok, %{courier: courier} = order} <- validate_order(order), | |
{:ok, true} <- courier_available?(courier), | |
{:ok, next_stage_slug} <- next_stage_slug_by(order), | |
{:persist_stage, {:ok, %Stage{} = stage}} | |
<- {:persist_stage, %{order: order} |> create_stage(next_stage_slug)}, | |
{:push_notification, :ok} | |
<- {:push_notification, push_notification(%{courier: courier, stage: stage})}, | |
{:emit_event, :ok} | |
<- {:emit_event, emit_event(%{courier: courier, stage: stage})} do | |
{:ok, stage} | |
else | |
e -> {:error, e} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment