From bf4934eacf82d599f41eddbf7466cad41c83a3a0 Mon Sep 17 00:00:00 2001 From: nelsonic Date: Wed, 5 Jun 2019 13:18:33 +0100 Subject: [PATCH] apply :assigned status if assignee is defined #1 --- lib/app/ctx/todo.ex | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/lib/app/ctx/todo.ex b/lib/app/ctx/todo.ex index d29cc08..a66a384 100644 --- a/lib/app/ctx/todo.ex +++ b/lib/app/ctx/todo.ex @@ -18,7 +18,17 @@ defmodule App.Ctx.Todo do @doc false def changeset(todo, attrs) do todo - |> cast(attrs, [:title, :status, :priority, :time_estimate, :deadline, :schedule, :assignee, :owner]) + |> cast(attrs, [:title, :status, :priority, :time_estimate, :deadline, + :schedule, :assignee, :owner]) |> validate_required([]) + |> status_assigned(todo) + end + + def status_assigned(changeset, todo) do + if(todo.assignee && todo.status == :unassigned) do + put_change(changeset, :status, :assigned) + else + changeset + end end end