Guest User

Untitled

a guest
Oct 22nd, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. defmodule DiscountScript do
  2. import Ecto.Query
  3.  
  4. def update_discounts() do
  5. ids = [5, 8, 10, 11, 15, 16, 17, 18, 19, 20, 25, 27, 28, 29]
  6. discounts = Reso.Repo.all(from d in Reso.Bookings.Discount, where: d.id in ^ids)
  7.  
  8. trueTypes = [:sibling, :volume, :bundle, :time_based]
  9. falseTypes = [:coupon]
  10.  
  11. Enum.reduce(discounts, %{succeeded: [], failed: []}, fn(d, acc) ->
  12. cond do
  13. Enum.member?(trueTypes, d.discount_type) == true ->
  14. IO.inspect(d, label: "in true types")
  15. # c = Reso.Bookings.Discount.changeset(d, %{shown: true, auto_applied: true}) |>
  16. # result = Reso.Repo.update(c)
  17. # case result do
  18. # {:ok, updated} -> Map.put(acc, :succeeded, [updated | acc.succeeded])
  19. # _ -> Map.put(acc, :failed, [d | acc.failed])
  20. # end
  21.  
  22. Enum.member?(falseTypes, d.discount_type) == true ->
  23. IO.inspect(d, label: "in false types")
  24. # c = Reso.Bookings.Discount.changeset(d, %{shown: false, auto_applied: false})
  25. # result = Reso.Repo.update(c)
  26. # case result do
  27. # {:ok, updated} -> Map.put(acc, :succeeded, [updated | acc.succeeded])
  28. # _ -> Map.put(acc, :failed, [d | acc.failed])
  29. # end
  30.  
  31. true ->
  32. IO.inspect(d, label: "type unknown")
  33. #Map.put(acc, :failed, [d | acc.failed])
  34. end
  35. end)
  36.  
  37. end
  38. end
Add Comment
Please, Sign In to add comment