Created
October 17, 2016 20:05
-
-
Save lasseebert/9126fdc778eb1838e7a2d3c5ddc74073 to your computer and use it in GitHub Desktop.
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
| defmodule MyApp.Users.Invite do | |
| alias MyApp.User | |
| alias MyApp.Repo | |
| @create_params [:email] | |
| def call(%{email: email}) do | |
| |> 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