2018-05-18 09:56:21 +02:00
|
|
|
defmodule Eventos.Actors.Member do
|
2018-01-14 17:56:50 +01:00
|
|
|
@moduledoc """
|
2018-05-18 09:56:21 +02:00
|
|
|
Represents the membership of an actor to a group
|
2018-01-14 17:56:50 +01:00
|
|
|
"""
|
2017-12-08 09:58:14 +01:00
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
2018-05-18 09:56:21 +02:00
|
|
|
alias Eventos.Actors.Member
|
|
|
|
alias Eventos.Actors.Actor
|
2017-12-08 09:58:14 +01:00
|
|
|
|
2018-06-06 17:42:53 +02:00
|
|
|
@primary_key false
|
2018-01-13 23:33:03 +01:00
|
|
|
schema "members" do
|
2018-07-27 10:45:35 +02: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 09:58:14 +01:00
|
|
|
|
|
|
|
timestamps()
|
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
2018-01-13 23:33:03 +01:00
|
|
|
def changeset(%Member{} = member, attrs) do
|
|
|
|
member
|
2018-06-06 17:42:53 +02:00
|
|
|
|> cast(attrs, [:role, :approved, :parent_id, :actor_id])
|
|
|
|
|> validate_required([:parent_id, :actor_id])
|
2017-12-08 09:58:14 +01:00
|
|
|
end
|
|
|
|
end
|