Skip to content

Commit

Permalink
Use coalesce to check if total_xp = nil
Browse files Browse the repository at this point in the history
  • Loading branch information
thortol committed Sep 11, 2024
1 parent 1183b15 commit c2945fa
Showing 1 changed file with 2 additions and 9 deletions.
11 changes: 2 additions & 9 deletions lib/cadet/assessments/assessments.ex
Original file line number Diff line number Diff line change
Expand Up @@ -1465,7 +1465,7 @@ defmodule Cadet.Assessments do
ans_xp
|> subquery
|> select([a], %{
total_xp: sum(a.total_xp)
total_xp: coalesce(sum(a.total_xp), 0)
})
|> Repo.one()

Expand All @@ -1476,15 +1476,8 @@ defmodule Cadet.Assessments do
submission.submitted_at
end

xp =
if is_integer(total.total_xp) do
total.total_xp
else
decimal_to_integer(total.total_xp)
end

xp_bonus =
if xp <= 0 do
if total.total_xp <= 0 do
0
else
if Timex.before?(cur_time, Timex.shift(assessment.open_at, hours: early_hours)) do
Expand Down

0 comments on commit c2945fa

Please sign in to comment.