Last active
December 2, 2016 20:39
-
-
Save sillypog/8ac1e5346f647843bfed01fb1f69644e to your computer and use it in GitHub Desktop.
Portmeirion.IdentifyController V1
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 find_or_create_user(params) do | |
user = find_user_by_login(params) || find_user_by_device(params) || find_user_by_prism(params) | |
... | |
end | |
defp find_user_by_login(%{"login_id" => login_id}), do: Repo.get_by(Portmeirion.User, %{login_id: login_id}) | |
defp find_user_by_login(_), do: nil | |
defp find_user_by_device(%{"device_id" => device_id}) do | |
Repo.one( | |
from d in Portmeirion.Device, | |
join: u in assoc(d, :user), | |
where: d.device_id == ^device_id, | |
select: %{warehouse_id: u.warehouse_id} | |
) | |
end | |
defp find_user_by_device(_), do: nil | |
# If we have no other information, then we will have to rely on prism_id | |
defp find_user_by_prism(%{"prism_id" => prism_id}), do: Repo.get_by(Portmeirion.User, %{prism_id: prism_id}) | |
defp find_user_by_prism(_), do: nil |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment