ObjectValidators: fix validate_required on embeds_many fields
This commit is contained in:
parent
d02c5f4480
commit
4576a5c440
2 changed files with 5 additions and 7 deletions
|
@ -45,9 +45,7 @@ def changeset(struct, data) do
|
|||
|
||||
struct
|
||||
|> cast(data, [:id, :type, :mediaType, :name, :blurhash])
|
||||
|> cast_embed(:url, with: &url_changeset/2)
|
||||
|> validate_inclusion(:type, ~w[Link Document Audio Image Video])
|
||||
|> validate_required([:type, :mediaType, :url])
|
||||
|> cast_embed(:url, with: &url_changeset/2, required: true)
|
||||
end
|
||||
|
||||
def url_changeset(struct, data) do
|
||||
|
@ -90,7 +88,7 @@ defp fix_url(data) do
|
|||
|
||||
defp validate_data(cng) do
|
||||
cng
|
||||
|> validate_inclusion(:type, ~w[Document Audio Image Video])
|
||||
|> validate_required([:mediaType, :url, :type])
|
||||
|> validate_inclusion(:type, ~w[Link Document Audio Image Video])
|
||||
|> validate_required([:type, :mediaType])
|
||||
end
|
||||
end
|
||||
|
|
|
@ -104,14 +104,14 @@ def changeset(struct, data) do
|
|||
|
||||
struct
|
||||
|> cast(data, __schema__(:fields) -- [:attachment, :tag])
|
||||
|> cast_embed(:attachment)
|
||||
|> cast_embed(:attachment, required: true)
|
||||
|> cast_embed(:tag)
|
||||
end
|
||||
|
||||
defp validate_data(data_cng) do
|
||||
data_cng
|
||||
|> validate_inclusion(:type, ["Audio", "Video"])
|
||||
|> validate_required([:id, :actor, :attributedTo, :type, :context, :attachment])
|
||||
|> validate_required([:id, :actor, :attributedTo, :type, :context])
|
||||
|> CommonValidations.validate_any_presence([:cc, :to])
|
||||
|> CommonValidations.validate_fields_match([:actor, :attributedTo])
|
||||
|> CommonValidations.validate_actor_presence()
|
||||
|
|
Loading…
Reference in a new issue