 defmodule RemoteRetro.User do
   use RemoteRetro.Web, :model
+  alias RemoteRetro.{Participation, Repo}
 
   @required_fields [
     :email,

    field :online_at, :integer, virtual: true
    field :token, :string, virtual: true

    has_many :participations, RemoteRetro.Participation
    has_many :retros, through: [:participations, :retro]

    timestamps(type: :utc_datetime)

  def upsert_record_from(oauth_info: oauth_info) do
    user_params = build_from_oauth_data(oauth_info)

    case Repo.get_by(__MODULE__, email: user_params["email"]) do
      nil -> %__MODULE__{}
      user_from_db -> user_from_db
    end
    |> __MODULE__.changeset(user_params)
    |> Repo.insert_or_update
  end

  defp build_from_oauth_data(user_info) do
