Usher.Invitation (Usher v0.2.0)
View SourceInvitation schema for Usher.
Represents an invitation with a unique token, expiration date, and usage tracking.
Summary
Functions
Changeset for creating and updating invitations.
Changeset for incrementing the joined count.
Types
@type t() :: %Usher.Invitation{ __meta__: term(), expires_at: DateTime.t(), id: Ecto.UUID.t(), inserted_at: DateTime.t(), joined_count: integer(), name: String.t() | nil, token: String.t(), updated_at: DateTime.t() }
Functions
Changeset for creating and updating invitations.
Options
:require_name
- Whether to require the name field (defaults to Config.name_required?())
Examples
iex> Usher.Invitation.changeset(%Usher.Invitation{}, %{
...> token: "abc123",
...> expires_at: ~U[2024-12-31 23:59:59Z]
...> })
%Ecto.Changeset{valid?: true}
iex> Usher.Invitation.changeset(%Usher.Invitation{}, %{})
%Ecto.Changeset{valid?: false, errors: [token: {"can't be blank", _}]}
iex> Usher.Invitation.changeset(%Usher.Invitation{}, %{token: "abc", expires_at: ~U[2024-12-31 23:59:59Z]}, require_name: true)
%Ecto.Changeset{valid?: false, errors: [name: {"can't be blank", _}]}
Changeset for incrementing the joined count.
This is for when a user successfully registers using the invitation.
Examples
iex> invitation = %Usher.Invitation{joined_count: 0}
iex> Usher.Invitation.increment_joined_count_changeset(invitation)
%Ecto.Changeset{changes: %{joined_count: 1}}