feat: make all member fields optional, so member creation can be continued later
This commit is contained in:
parent
d4c7af558d
commit
800a55d42f
8 changed files with 286 additions and 40 deletions
|
|
@ -60,11 +60,7 @@ defmodule Mv.Membership.Member do
|
|||
end
|
||||
|
||||
validations do
|
||||
# Required fields are covered by allow_nil? false
|
||||
|
||||
# First name and last name must not be empty
|
||||
validate present(:first_name)
|
||||
validate present(:last_name)
|
||||
# All fields are optional - no required validations
|
||||
|
||||
# Birth date not in the future
|
||||
validate compare(:birth_date, less_than_or_equal_to: &Date.utc_today/0),
|
||||
|
|
@ -93,32 +89,31 @@ defmodule Mv.Membership.Member do
|
|||
|
||||
# Email validation with EctoCommons.EmailValidator (only for member_email)
|
||||
validate fn changeset, _ ->
|
||||
member_email = Ash.Changeset.get_attribute(changeset, :member_email)
|
||||
member_email = Ash.Changeset.get_attribute(changeset, :member_email)
|
||||
|
||||
changeset2 =
|
||||
{%{}, %{email: :string}}
|
||||
|> Ecto.Changeset.cast(%{email: member_email}, [:email])
|
||||
|> EctoCommons.EmailValidator.validate_email(:email, checks: [:html_input, :pow])
|
||||
changeset2 =
|
||||
{%{}, %{email: :string}}
|
||||
|> Ecto.Changeset.cast(%{email: member_email}, [:email])
|
||||
|> EctoCommons.EmailValidator.validate_email(:email, checks: [:html_input, :pow])
|
||||
|
||||
if changeset2.valid? do
|
||||
:ok
|
||||
else
|
||||
{:error, field: :member_email, message: "is not a valid email"}
|
||||
end
|
||||
end, where: [present(:member_email)]
|
||||
if changeset2.valid? do
|
||||
:ok
|
||||
else
|
||||
{:error, field: :member_email, message: "is not a valid email"}
|
||||
end
|
||||
end,
|
||||
where: [present(:member_email)]
|
||||
end
|
||||
|
||||
attributes do
|
||||
uuid_v7_primary_key :id
|
||||
|
||||
attribute :first_name, :string do
|
||||
allow_nil? false
|
||||
constraints min_length: 1
|
||||
allow_nil? true
|
||||
end
|
||||
|
||||
attribute :last_name, :string do
|
||||
allow_nil? false
|
||||
constraints min_length: 1
|
||||
allow_nil? true
|
||||
end
|
||||
|
||||
# Internal email field for members without users
|
||||
|
|
@ -176,5 +171,4 @@ defmodule Mv.Membership.Member do
|
|||
calculations do
|
||||
calculate :email, :string, Mv.Membership.MemberEmailCalculation
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue