New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create manual Orders #16

Open
wants to merge 4 commits into
base: master
from

Conversation

3 participants
@eliasousa
Copy link
Owner

eliasousa commented Dec 31, 2018

Index

screen shot 2018-12-31 at 3 20 08 pm

New

screen shot 2018-12-31 at 3 20 28 pm

@eliasousa eliasousa added this to In progress in Voo Pay Dec 31, 2018

end

defp set_order_attrs(%{"taxi_id" => taxi_id, "monthly_date" => monthly_date} = order_attrs) do
taxi = Accounts.get_taxi!(taxi_id)

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator
taxi = Accounts.get_taxi!(taxi_id) |> Repo.preload(:plan)
  

💅


def index(conn, params) do
page = Sales.list_orders(params)
orders = Repo.preload(page.entries, :taxi)

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator

Dá pra fazer o preload no método list_orders(params), não sendo necessário o alias do Repo

def list_orders(params) do
    Order
    |> order_by(desc: :inserted_at)
    |> preload(:taxi)
    |> Repo.paginate(params)
end

...

render(conn, "index.html", orders: page.entries, page: page)
end

def new(conn, _params) do
changeset = Sales.change_order(%Order{})

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator

Pode fazer a chamada do método sem parâmetro mesmo e remover o alias do Order, já que o struct é um dos parâmetros defaults dele.

@@ -24,11 +24,14 @@ defmodule BerlimWeb.Router do
end

scope "/", BerlimWeb do
pipe_through([:browser, :ensure_admin])
pipe_through([:browser])
# pipe_through([:browser, :ensure_admin])

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator

👀


test "create_order/1 with valid data creates a order" do
taxi = insert(:taxi)
taxi = Repo.preload(taxi, :plan)

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator
taxi = Repo.preload(insert(:taxi), :plan)

💅

describe "GET /index, when user is an admin" do
setup [:authenticate_admin]

test "lists all admins", %{conn: conn} do

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator

😞


defp create_order(_) do
order = insert(:order)
{:ok, order: order}

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator
{:ok, order: insert(:order)}

💅


defp authenticate_admin(%{conn: conn}) do
conn = authenticate(conn)
%{conn: conn}

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator
%{conn: authenticate(conn)}

💅

|> cast(attrs, [:value, :status, :type, :approved_at, :monthly_date])
|> validate_required([:value, :status, :type, :monthly_date])
|> cast(attrs, [:value, :status, :type, :approved_at, :monthly_date, :taxi_id])
|> validate_required([:value, :status, :type, :monthly_date, :taxi_id])

This comment has been minimized.

@danpassoss

danpassoss Jan 1, 2019

Collaborator

Nesse caso, acho que seria melhor usar o assoc_constraint, que irá verificar se o Táxi associado à Order existe.
Inclusive, na documentação do validate_required, eles recomendam não usar esse método para validar associações que são requeridas.

@danpassoss

This comment has been minimized.

Copy link
Collaborator

danpassoss commented Jan 1, 2019

Fiquei com uma dúvida, vai ser feita alguma validação para verificar se já existe uma Order criada/paga em uma data específica , impossibilitando de criar outra Order para a mesma data?

@@ -0,0 +1,48 @@
$(function() {

This comment has been minimized.

@thiagogsr

thiagogsr Jan 2, 2019

Collaborator

o nome desse arquivo está genérico mas o comportamento dele é específico para essa tela


defmodule Status do
@moduledoc false
use Exnumerator, values: [:approved, :pending, :refused]
use Exnumerator, values: [:approved, :pending, :refused, :paid]

This comment has been minimized.

@thiagogsr

thiagogsr Jan 2, 2019

Collaborator

qual a diferença de approved para paid?

Map.merge(order_attrs, %{
"monthly_date" => parse_date(monthly_date),
"value" => taxi.plan.value,
"status" => "paid",

This comment has been minimized.

@thiagogsr

thiagogsr Jan 2, 2019

Collaborator

não entendi essa order manual, qual não será manual? se o cara passar na máquina de cartão dentro da voo, também será manual, vc n está deixando escolher a forma de pagamento, o status, etc

This comment has been minimized.

@thiagogsr

thiagogsr Jan 2, 2019

Collaborator

se essa order manual for só para dinheiro, acho que merece um módulo específico para criar orders em dinheiro

"""

def parse_date(date) do
case Timex.parse(date, "{D}/{0M}/{YYYY}") do

This comment has been minimized.

@thiagogsr

thiagogsr Jan 2, 2019

Collaborator

acho que precisa o 0D, n? se for dia 01 por exemplo

@MarcusSky MarcusSky removed their request for review Jan 13, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment