Actual vote count in poll view
This commit is contained in:
parent
a53d062730
commit
f28747858b
1 changed files with 8 additions and 8 deletions
|
@ -338,8 +338,6 @@ def render("poll.json", %{object: object} = _opts) do
|
||||||
(object.data["closed"] || object.data["endTime"])
|
(object.data["closed"] || object.data["endTime"])
|
||||||
|> NaiveDateTime.from_iso8601!()
|
|> NaiveDateTime.from_iso8601!()
|
||||||
|
|
||||||
votes_count = object.data["votes_count"] || 0
|
|
||||||
|
|
||||||
expired =
|
expired =
|
||||||
end_time
|
end_time
|
||||||
|> NaiveDateTime.compare(NaiveDateTime.utc_now())
|
|> NaiveDateTime.compare(NaiveDateTime.utc_now())
|
||||||
|
@ -348,12 +346,14 @@ def render("poll.json", %{object: object} = _opts) do
|
||||||
_ -> false
|
_ -> false
|
||||||
end
|
end
|
||||||
|
|
||||||
options =
|
{options, votes_count} =
|
||||||
Enum.map(options, fn %{"name" => name} = option ->
|
Enum.map_reduce(options, 0, fn %{"name" => name} = option, count ->
|
||||||
%{
|
current_count = option["replies"]["totalItems"] || 0
|
||||||
title: HTML.strip_tags(name),
|
|
||||||
votes_count: option["replies"]["votes_count"] || 0
|
{%{
|
||||||
}
|
title: HTML.strip_tags(name),
|
||||||
|
votes_count: current_count
|
||||||
|
}, current_count + count}
|
||||||
end)
|
end)
|
||||||
|
|
||||||
%{
|
%{
|
||||||
|
|
Loading…
Reference in a new issue