2018-05-18 07:56:21 +00:00
|
|
|
defmodule Eventos.Actors.Member do
|
2018-01-14 16:56:50 +00:00
|
|
|
@moduledoc """
|
2018-05-18 07:56:21 +00:00
|
|
|
Represents the membership of an actor to a group
|
2018-01-14 16:56:50 +00:00
|
|
|
"""
|
2017-12-08 08:58:14 +00:00
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
2018-05-18 07:56:21 +00:00
|
|
|
alias Eventos.Actors.Member
|
|
|
|
alias Eventos.Actors.Actor
|
2017-12-08 08:58:14 +00:00
|
|
|
|
2018-06-06 15:42:53 +00:00
|
|
|
@primary_key false
|
2018-01-13 22:33:03 +00:00
|
|
|
schema "members" do
|
2018-07-27 08:45:35 +00:00
|
|
|
field(:approved, :boolean, default: true)
|
|
|
|
# 0 : Member, 1 : Moderator, 2 : Admin
|
|
|
|
field(:role, :integer, default: 0)
|
|
|
|
belongs_to(:parent, Actor)
|
|
|
|
belongs_to(:actor, Actor)
|
2017-12-08 08:58:14 +00:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2018-01-13 22:33:03 +00:00
|
|
|
def changeset(%Member{} = member, attrs) do
|
|
|
|
member
|
2018-06-06 15:42:53 +00:00
|
|
|
|> cast(attrs, [:role, :approved, :parent_id, :actor_id])
|
|
|
|
|> validate_required([:parent_id, :actor_id])
|
2017-12-08 08:58:14 +00:00
|
|
|
end
|
|
|
|
end
|