forked from AkkomaGang/akkoma
Allow for varying name fields
This commit is contained in:
parent
5c48fe1138
commit
2cc6b1e1bd
1 changed files with 20 additions and 3 deletions
|
@ -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])
|
||||
|
|
Loading…
Reference in a new issue