Skip to content

Instantly share code, notes, and snippets.

@lasseebert
Created October 17, 2016 20:05
Show Gist options
  • Select an option

  • Save lasseebert/9126fdc778eb1838e7a2d3c5ddc74073 to your computer and use it in GitHub Desktop.

Select an option

Save lasseebert/9126fdc778eb1838e7a2d3c5ddc74073 to your computer and use it in GitHub Desktop.
defmodule MyApp.Users.Invite do
alias MyApp.User
alias MyApp.Repo
@create_params [:email]
def call(%{email: email}) do
email
|> build_changeset
|> create_user
end
defp build_changeset(email) do
params = %{email: email}
%User{}
|> Ecto.Changeset.cast(params, @create_params)
|> Ecto.Changeset.unique_constraint(:email)
end
defp create_user(changeset) do
changeset
|> Repo.insert
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment