2019-08-28 12:53:01 -04:00
|
|
|
defmodule Philomena.Donations.Donation do
|
|
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
|
2019-11-16 18:42:41 -05:00
|
|
|
alias Philomena.Users.User
|
|
|
|
|
2019-08-28 12:53:01 -04:00
|
|
|
schema "donations" do
|
2019-11-16 18:42:41 -05:00
|
|
|
belongs_to :user, User
|
2019-08-28 12:53:01 -04:00
|
|
|
|
|
|
|
field :email, :string
|
|
|
|
field :amount, :decimal
|
|
|
|
field :fee, :decimal
|
|
|
|
field :txn_id, :string
|
2019-12-16 22:24:40 -05:00
|
|
|
field :receipt_id, :string
|
2019-08-28 12:53:01 -04:00
|
|
|
field :note, :string
|
|
|
|
|
2021-01-18 13:01:03 -05:00
|
|
|
timestamps(inserted_at: :created_at, type: :utc_datetime)
|
2019-08-28 12:53:01 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
@doc false
|
|
|
|
def changeset(donation, attrs) do
|
|
|
|
donation
|
2019-12-16 22:24:40 -05:00
|
|
|
|> cast(attrs, [:email, :amount, :note, :user_id])
|
2019-08-28 12:53:01 -04:00
|
|
|
|> validate_required([])
|
2019-12-16 22:24:40 -05:00
|
|
|
|> foreign_key_constraint(:user_id, name: :fk_rails_5470822a00)
|
2019-08-28 12:53:01 -04:00
|
|
|
end
|
|
|
|
end
|