From 0b7146ba32789d9c3081d28099ff0864980c05e0 Mon Sep 17 00:00:00 2001 From: shibao Date: Sat, 18 Mar 2023 01:05:09 -0400 Subject: [PATCH] fix shot record error message --- CHANGELOG.md | 1 + lib/cannery/activity_log/shot_group.ex | 17 ++++++----------- 2 files changed, 7 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d0a65574..7a100790 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/lib/cannery/activity_log/shot_group.ex b/lib/cannery/activity_log/shot_group.ex index 3cb4bdf8..f4a66ad5 100644 --- a/lib/cannery/activity_log/shot_group.ex +++ b/lib/cannery/activity_log/shot_group.ex @@ -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