ensure commission items are sorted by price

This commit is contained in:
byte[] 2020-01-01 21:35:37 -05:00
parent 5650f09bc0
commit 2e7937cbc3
2 changed files with 8 additions and 4 deletions

View file

@ -16,13 +16,17 @@ defmodule PhilomenaWeb.Profile.CommissionController do
def show(conn, _params) do def show(conn, _params) do
commission = conn.assigns.user.commission commission = conn.assigns.user.commission
item_descriptions = items =
commission.items commission.items
|> Enum.sort(&Decimal.cmp(&1.base_price, &2.base_price) != :gt)
item_descriptions =
items
|> Enum.map(&%{body: &1.description }) |> Enum.map(&%{body: &1.description })
|> Renderer.render_collection(conn) |> Renderer.render_collection(conn)
item_add_ons = item_add_ons =
commission.items items
|> Enum.map(&%{body: &1.add_ons}) |> Enum.map(&%{body: &1.add_ons})
|> Renderer.render_collection(conn) |> Renderer.render_collection(conn)
@ -45,7 +49,7 @@ defmodule PhilomenaWeb.Profile.CommissionController do
will_not_create: will_not_create will_not_create: will_not_create
} }
items = Enum.zip([item_descriptions, item_add_ons, commission.items]) items = Enum.zip([item_descriptions, item_add_ons, items])
render(conn, "show.html", title: "Showing Commission", rendered: rendered, commission: commission, items: items, layout_class: "layout--wide") render(conn, "show.html", title: "Showing Commission", rendered: rendered, commission: commission, items: items, layout_class: "layout--wide")
end end

View file

@ -5,7 +5,7 @@ defmodule Textile.Parser do
def parse(parser, input) do def parse(parser, input) do
parser = Map.put(parser, :state, %{}) parser = Map.put(parser, :state, %{})
with {:ok, tokens, _1, _2, _3, _4} <- Lexer.lex(String.trim(input)), with {:ok, tokens, _1, _2, _3, _4} <- Lexer.lex(String.trim(input || "")),
{:ok, tree, []} <- repeat(&textile/2, parser, tokens) {:ok, tree, []} <- repeat(&textile/2, parser, tokens)
do do
partial_flatten(tree) partial_flatten(tree)