Last active
November 30, 2016 00:57
-
-
Save sillypog/521109b2b3e5442a39f50e8194bdb10f to your computer and use it in GitHub Desktop.
Portmeirion.IdentifyController V5
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defp where_clause(query, params) do | |
allowed_params = ~w(login_id facebook_id device_id prism_id) | |
key_values = params | |
|> Enum.filter(fn({key, _}) -> Enum.member?(allowed_params, key) end) | |
|> Enum.map(fn({key, value}) -> {String.to_existing_atom(key), cast_param(key, value)} end) # or_where expects list of tuples | |
|> Enum.sort # Ensure device_id is always first if present | |
where_fragment(query, key_values) | |
end | |
defp where_fragment(query, [{:device_id, device_id} | other_filters]) do | |
from [u, d] in query, | |
where: d.device_id == ^device_id, | |
or_where: ^other_filters | |
end | |
defp where_fragment(query, filters) do | |
from u in query, | |
or_where: ^filters | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment