SHARE
TWEET

Untitled

a guest Jun 19th, 2019 56 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def user_contacts(provider_id, filter) do
  2.   query =
  3.     from(
  4.       u in User,
  5.       preload: [:groups],
  6.       where: u.provider_id == ^provider_id and u.type != "company"
  7.     )
  8.  
  9.   query
  10.   |> filter_sector(filter)
  11.   |> filter_availability(filter)
  12. end
  13.  
  14. defp filter_sector(query, %{"sector" => "Asset Management & Investment Funds"}) do
  15.   query
  16.   |> join(:inner, [u], p in Profile, p.user_id == u.id)
  17.   |> where([u, p], fragment("(sectors->>'asset' = ?)", "true"))
  18. end
  19.  
  20. defp filter_availability(query, %{"availability" => "now"}) do
  21.   query
  22.   |> join(:inner, [u], p in Profile, p.user_id == u.id)
  23.   |> where([u, p], ^Date.utc_today >= p.placement_availability)
  24. end
  25.      
  26. from(
  27.   q in query,
  28.   join: p in Profile,
  29.   on: p.user_id == q.id,
  30.   where: fragment("(sectors->>'asset' = ?)", "true")
  31. )
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top