Skip to content
This repository was archived by the owner on Nov 8, 2022. It is now read-only.

Commit 85b0986

Browse files
committed
refactor(comment-curd): clean multi tasks
1 parent f4f669d commit 85b0986

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

lib/groupher_server/cms/delegates/comment_curd.ex

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,15 +92,7 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
9292
ORM.delete(comment)
9393
end)
9494
|> Multi.run(:update_floor, fn _, _ ->
95-
Repo.update_all(
96-
from(p in action.reactor, where: p.id > ^comment.id),
97-
inc: [floor: -1]
98-
)
99-
|> done()
100-
|> case do
101-
{:ok, _} -> {:ok, comment}
102-
{:error, _} -> {:error, ""}
103-
end
95+
exec_update_floor(action.reactor, comment)
10496
end)
10597
|> Repo.transaction()
10698
|> delete_comment_result()
@@ -185,6 +177,18 @@ defmodule GroupherServer.CMS.Delegate.CommentCURD do
185177
{:error, [message: "update follor fails", code: ecode(:delete_fails)]}
186178
end
187179

180+
defp exec_update_floor(queryable, comment) do
181+
Repo.update_all(
182+
from(p in queryable, where: p.id > ^comment.id),
183+
inc: [floor: -1]
184+
)
185+
|> done()
186+
|> case do
187+
{:ok, _} -> {:ok, comment}
188+
{:error, _} -> {:error, ""}
189+
end
190+
end
191+
188192
# simulate a join connection
189193
# TODO: use Multi task to refactor
190194
# TODO: refactor boilerplate code

0 commit comments

Comments
 (0)