fix shot record error message

This commit is contained in:
shibao 2023-03-18 01:05:09 -04:00
parent c0441957b6
commit 0b7146ba32
2 changed files with 7 additions and 11 deletions

View File

@ -2,6 +2,7 @@
- Improve accessibility
- Code quality improvements
- Fix dead link of example bullet abbreviations
- Fix inaccurate error message when updating shot records
# v0.8.3
- Improve some styles

View File

@ -115,18 +115,13 @@ defmodule Cannery.ActivityLog.ShotGroup do
new_shot_group_count = changeset |> Changeset.get_field(:count)
shot_diff_to_add = new_shot_group_count - count
cond do
shot_diff_to_add > ammo_group_count ->
error =
dgettext("errors", "Count must be less than %{count} shots", count: ammo_group_count)
if shot_diff_to_add > ammo_group_count do
error =
dgettext("errors", "Count can be at most %{count} shots", count: ammo_group_count + count)
changeset |> Changeset.add_error(:count, error)
new_shot_group_count <= 0 ->
changeset |> Changeset.add_error(:count, dgettext("errors", "Count must be at least 1"))
true ->
changeset
changeset |> Changeset.add_error(:count, error)
else
changeset
end
end
end