55 lines
1.2 KiB
Elixir
55 lines
1.2 KiB
Elixir
defmodule TuskerPush.Registration do
|
|
use Ecto.Schema
|
|
|
|
import Ecto.Changeset
|
|
|
|
@type t() :: %__MODULE__{
|
|
id: Ecto.UUID.t(),
|
|
storekit_original_transaction_id: String.t(),
|
|
apns_environment: String.t(),
|
|
apns_device_token: String.t(),
|
|
push_version: integer(),
|
|
inserted_at: NaiveDateTime.t(),
|
|
updated_at: NaiveDateTime.t()
|
|
}
|
|
|
|
@primary_key {:id, Ecto.UUID, autogenerate: true}
|
|
|
|
schema "registrations" do
|
|
field :storekit_original_transaction_id, :string
|
|
|
|
field :apns_environment, Ecto.Enum, values: [:production, :development]
|
|
# hex-encoded
|
|
field :apns_device_token, :string
|
|
|
|
field :push_version, :integer
|
|
|
|
timestamps()
|
|
end
|
|
|
|
@create_fields [
|
|
:storekit_original_transaction_id,
|
|
:apns_environment,
|
|
:apns_device_token,
|
|
:push_version
|
|
]
|
|
|
|
def create_changeset(registration \\ %__MODULE__{}, params) do
|
|
registration
|
|
|> cast(params, @create_fields)
|
|
|> validate_required(@create_fields)
|
|
end
|
|
|
|
@update_fields [
|
|
:apns_environment,
|
|
:apns_device_token,
|
|
:push_version
|
|
]
|
|
|
|
def update_changeset(registration, params) do
|
|
registration
|
|
|> cast(params, @update_fields)
|
|
|> validate_required(@update_fields)
|
|
end
|
|
end
|