fix ammo type changesets
This commit is contained in:
parent
41bcc2f456
commit
5b5fd7173b
@ -141,11 +141,8 @@ defmodule Cannery.Ammo do
|
|||||||
"""
|
"""
|
||||||
@spec create_ammo_type(attrs :: map(), User.t()) ::
|
@spec create_ammo_type(attrs :: map(), User.t()) ::
|
||||||
{:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.new_ammo_type())}
|
{:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.new_ammo_type())}
|
||||||
def create_ammo_type(attrs \\ %{}, %User{id: user_id}) do
|
def create_ammo_type(attrs \\ %{}, %User{} = user),
|
||||||
%AmmoType{}
|
do: %AmmoType{} |> AmmoType.create_changeset(user, attrs) |> Repo.insert()
|
||||||
|> AmmoType.create_changeset(attrs |> Map.put("user_id", user_id))
|
|
||||||
|> Repo.insert()
|
|
||||||
end
|
|
||||||
|
|
||||||
@doc """
|
@doc """
|
||||||
Updates a ammo_type.
|
Updates a ammo_type.
|
||||||
|
@ -105,10 +105,12 @@ defmodule Cannery.Ammo.AmmoType do
|
|||||||
]
|
]
|
||||||
|
|
||||||
@doc false
|
@doc false
|
||||||
@spec create_changeset(new_ammo_type(), attrs :: map()) :: Changeset.t(new_ammo_type())
|
@spec create_changeset(new_ammo_type(), User.t(), attrs :: map()) ::
|
||||||
def create_changeset(ammo_type, attrs) do
|
Changeset.t(new_ammo_type())
|
||||||
|
def create_changeset(ammo_type, %User{id: user_id}, attrs) do
|
||||||
ammo_type
|
ammo_type
|
||||||
|> cast(attrs, [:user_id | changeset_fields()])
|
|> change(user_id: user_id)
|
||||||
|
|> cast(attrs, changeset_fields())
|
||||||
|> validate_required([:name, :user_id])
|
|> validate_required([:name, :user_id])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ msgstr ""
|
|||||||
"%{multiplier}"
|
"%{multiplier}"
|
||||||
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
#: lib/cannery/ammo.ex:407
|
#: lib/cannery/ammo.ex:404
|
||||||
msgid "Invalid multiplier"
|
msgid "Invalid multiplier"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
#: lib/cannery/ammo.ex:407
|
#: lib/cannery/ammo.ex:404
|
||||||
msgid "Invalid multiplier"
|
msgid "Invalid multiplier"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -170,7 +170,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
#: lib/cannery/ammo.ex:407
|
#: lib/cannery/ammo.ex:404
|
||||||
msgid "Invalid multiplier"
|
msgid "Invalid multiplier"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -181,7 +181,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
|||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
#: lib/cannery/ammo.ex:407
|
#: lib/cannery/ammo.ex:404
|
||||||
msgid "Invalid multiplier"
|
msgid "Invalid multiplier"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
@ -187,7 +187,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
|||||||
msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}"
|
msgstr "Nombre de copies invalide, doit être 1 et %{max}. Été %{multiplier}"
|
||||||
|
|
||||||
#, elixir-autogen, elixir-format
|
#, elixir-autogen, elixir-format
|
||||||
#: lib/cannery/ammo.ex:407
|
#: lib/cannery/ammo.ex:404
|
||||||
msgid "Invalid multiplier"
|
msgid "Invalid multiplier"
|
||||||
msgstr ""
|
msgstr ""
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user