Allow for varying name fields

This commit is contained in:
FloatingGhost 2022-01-07 17:35:56 +00:00
parent 5c48fe1138
commit 2cc6b1e1bd

View file

@ -69,7 +69,12 @@ def changeset(struct, %{"type" => "Emoji"} = data) do
end
def changeset(struct, %{"type" => "Book"} = data) do
data = Map.put(data, "name", data["title"])
data =
if Map.has_key?(data, "title") do
Map.put(data, "name", data["title"])
else
data
end
struct
|> cast(data, [:type, :name])
@ -77,7 +82,14 @@ def changeset(struct, %{"type" => "Book"} = data) do
end
def changeset(struct, %{"type" => "Edition"} = data) do
data = Map.put(data, "name", data["title"])
# Sometimes it's title, sometimes name
# Don't ask me.
data =
if Map.has_key?(data, "title") do
Map.put(data, "name", data["title"])
else
data
end
struct
|> cast(data, [:type, :name])
@ -85,7 +97,12 @@ def changeset(struct, %{"type" => "Edition"} = data) do
end
def changeset(struct, %{"type" => "Work"} = data) do
data = Map.put(data, "name", data["title"])
data =
if Map.has_key?(data, "title") do
Map.put(data, "name", data["title"])
else
data
end
struct
|> cast(data, [:type, :name])