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()) ::
|
||||
{:ok, AmmoType.t()} | {:error, Changeset.t(AmmoType.new_ammo_type())}
|
||||
def create_ammo_type(attrs \\ %{}, %User{id: user_id}) do
|
||||
%AmmoType{}
|
||||
|> AmmoType.create_changeset(attrs |> Map.put("user_id", user_id))
|
||||
|> Repo.insert()
|
||||
end
|
||||
def create_ammo_type(attrs \\ %{}, %User{} = user),
|
||||
do: %AmmoType{} |> AmmoType.create_changeset(user, attrs) |> Repo.insert()
|
||||
|
||||
@doc """
|
||||
Updates a ammo_type.
|
||||
|
@ -105,10 +105,12 @@ defmodule Cannery.Ammo.AmmoType do
|
||||
]
|
||||
|
||||
@doc false
|
||||
@spec create_changeset(new_ammo_type(), attrs :: map()) :: Changeset.t(new_ammo_type())
|
||||
def create_changeset(ammo_type, attrs) do
|
||||
@spec create_changeset(new_ammo_type(), User.t(), attrs :: map()) ::
|
||||
Changeset.t(new_ammo_type())
|
||||
def create_changeset(ammo_type, %User{id: user_id}, attrs) do
|
||||
ammo_type
|
||||
|> cast(attrs, [:user_id | changeset_fields()])
|
||||
|> change(user_id: user_id)
|
||||
|> cast(attrs, changeset_fields())
|
||||
|> validate_required([:name, :user_id])
|
||||
end
|
||||
|
||||
|
@ -188,7 +188,7 @@ msgstr ""
|
||||
"%{multiplier}"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:407
|
||||
#: lib/cannery/ammo.ex:404
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
@ -171,7 +171,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:407
|
||||
#: lib/cannery/ammo.ex:404
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
@ -170,7 +170,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:407
|
||||
#: lib/cannery/ammo.ex:404
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
@ -181,7 +181,7 @@ msgid "Invalid number of copies, must be between 1 and %{max}. Was %{multiplier}
|
||||
msgstr ""
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:407
|
||||
#: lib/cannery/ammo.ex:404
|
||||
msgid "Invalid multiplier"
|
||||
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}"
|
||||
|
||||
#, elixir-autogen, elixir-format
|
||||
#: lib/cannery/ammo.ex:407
|
||||
#: lib/cannery/ammo.ex:404
|
||||
msgid "Invalid multiplier"
|
||||
msgstr ""
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user