<commit_before>defmodule Appointments.Employee do
  use Appointments.Web, :model

  # TODO(krummi): alias Openmaize.DB

  schema "employees" do
    field :name, :string
    field :phone, :string
    field :bio, :string
    field :avatar_url, :string

    # Openmaize stuff
    field :email, :string
    field :password, :string, virtual: true
    field :password_hash, :string

    # Email confirmation
    field :confirmation_token, :string
    field :confirmation_sent_at, Ecto.DateTime
    field :confirmed_at, Ecto.DateTime

    # Password reset fields
    field :reset_token, :string
    field :reset_sent_at, Ecto.DateTime

    belongs_to :company, Appointments.Company

    timestamps
  end

  @required_fields ~w(name email password_hash)
  @optional_fields ~w(phone bio avatar_url
                      confirmation_token confirmation_sent_at confirmed_at
                      reset_token reset_sent_at)

  @doc """
  Creates a changeset based on the `model` and `params`.

  If no params are provided, an invalid changeset is returned
  with no validation performed.
  """
  def changeset(model, params \\ :empty) do
    # TODO(krummi): validations
    model
    |> cast(params, @required_fields, @optional_fields)
    |> unique_constraint(:email)
  end
end<commit_msg>Role validation, field changes, openmaize functions<commit_after>defmodule Appointments.Employee do
  use Appointments.Web, :model

  alias Openmaize.DB

  schema "employees" do
    field :email, :string
    field :name, :string
    field :phone, :string
    field :bio, :string
    field :avatar_url, :string
    field :role, :string

    # Authentication
    field :password, :string, virtual: true
    field :password_hash, :string

    # Email confirmation
    field :confirmation_token, :string
    field :confirmation_sent_at, Ecto.DateTime
    field :confirmed_at, Ecto.DateTime

    # Password reset fields
    field :reset_token, :string
    field :reset_sent_at, Ecto.DateTime

    belongs_to :company, Appointments.Company

    timestamps
  end

  @required_fields ~w(name email role)
  @optional_fields ~w(phone bio avatar_url
                      password_hash
                      confirmation_token confirmation_sent_at confirmed_at
                      reset_token reset_sent_at)

  @doc """
  Creates a changeset based on the `model` and `params`.

  If no params are provided, an invalid changeset is returned
  with no validation performed.
  """
  def changeset(model, params \\ :empty) do
    # TODO(krummi): validations
    model
    |> cast(params, @required_fields, @optional_fields)
    |> validate_inclusion(:role, ["restricted", "self", "full"])
    |> unique_constraint(:email)
  end

  def auth_changeset(model, params, key) do
    model
    |> changeset(params)
    |> DB.add_password_hash(params)
    |> DB.add_confirm_token(key)
  end

  def reset_changeset(model, params, key) do
    model
    |> cast(params, ~w(email), [])
    |> DB.add_reset_token(key)
  end

end
{'fraction_non_alphanumeric': 0.0875251509054326, 'fraction_numerical': 0.0, 'mean_word_length': 3.237215909090909, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5751096', 'n_tokens_mistral': 936, 'n_tokens_neox': 892, 'n_words': 256}