Is it possible to check if a string parameter being passed in is an integer? For example I need to retrieve a model based either on its id ("12345") or external_id ("eUv9wWzZ48bMZsuII6ivCle2NHgIEPoMLWC9ioDV"). Is this possible to achieve? I tried is_integer but that returns false as it doesn't try to parse a string.
def call(%{params: %{"id" => id}} = conn, module) when is_atom(module) and is_integer(id) do
ZB.Repo.get!(module, id)
|> check(conn)
end
def call(%{params: %{"id" => id}} = conn, module) when is_atom(module) do
ZB.Repo.get_by!(module, external_id: id)
end