@@ -12,6 +12,9 @@ defmodule CodeCorps.Messages do
12
12
Repo
13
13
}
14
14
alias Ecto . { Changeset , Queryable }
15
+
16
+ @ reopened "reopened"
17
+ @ closed "closed"
15
18
16
19
@ doc ~S"""
17
20
Lists pre-scoped `CodeCorps.Message` records filtered by parameters.
@@ -55,19 +58,22 @@ defmodule CodeCorps.Messages do
55
58
@ doc ~S"""
56
59
Updates a `CodeCorps.Conversation` record
57
60
"""
61
+ def update_conversation ( conversation , % { status: @ reopened } = params ) do
62
+ add_part ( % { "conversation_id" => conversation . id , "body" => "reopened" , "author_id"
63
+ => conversation . user_id , "part_type" => "reopened" } )
64
+ conversation |> Conversation . update_changeset ( params ) |> Repo . update
65
+ end
66
+
67
+ def update_conversation ( conversation , % { status: @ closed } = params ) do
68
+ add_part ( % { "conversation_id" => conversation . id , "body" => "closed" , "author_id"
69
+ => conversation . user_id , "part_type" => "closed" } )
70
+ conversation |> Conversation . update_changeset ( params ) |> Repo . update
71
+ end
72
+
58
73
def update_conversation ( conversation , params ) do
59
- % { status: status } = params
60
- case status do
61
- "reopened" ->
62
- add_part ( % { "conversation_id" => conversation . id , "body" => "reopened" , "author_id"
63
- => conversation . user_id , "part_type" => "reopened" } )
64
- "closed" ->
65
- add_part ( % { "conversation_id" => conversation . id , "body" => "closed" , "author_id"
66
- => conversation . user_id , "part_type" => "closed" } )
67
-
68
- end
69
74
conversation |> Conversation . update_changeset ( params ) |> Repo . update
70
75
end
76
+
71
77
72
78
@ doc ~S"""
73
79
Gets a `CodeCorps.ConversationPart` record
0 commit comments