Skip to content

Instantly share code, notes, and snippets.

@olivermt
Created September 25, 2015 12:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save olivermt/c9ebe22e537c0aa564e6 to your computer and use it in GitHub Desktop.
Save olivermt/c9ebe22e537c0aa564e6 to your computer and use it in GitHub Desktop.
def update_company(company, company_params) do
changeset = Company.changeset(company, company_params)
if Ecto.Changeset.fetch_change(changeset, :shortname) != :error do
Logger.debug "Shortname changed"
#TODO dont allow shortname change if shortname is in use in video addresses
:ok
end
Repo.transaction( fn ->
case Repo.update(changeset) do
{:ok, company} ->
if Ecto.Changeset.fetch_change(changeset, :name) != :error or Ecto.Changeset.fetch_change(changeset, :country) != :error do
Logger.debug "Pushing seevia changes"
case seevia_api.update_company(company) do
{:ok, _ } ->
company
{:error, reason } ->
Logger.error "Seevia API write failed for company.id #{company.id}, reason: #{reason}"
Repo.rollback("Seevia api write failed")
end
else
company
end
{:error, changeset} ->
Repo.rollback(changeset)
end
end)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment