Skip to content

Commit

Permalink
feat: counts for day field in badge table
Browse files Browse the repository at this point in the history
  • Loading branch information
ruilopesm committed Feb 4, 2024
1 parent 47a4c96 commit 28e20fa
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
6 changes: 4 additions & 2 deletions lib/mix/tasks/gen.badges.ex
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ defmodule Mix.Tasks.Gen.Badges do
end_badge,
image_path,
type,
tokens
tokens,
counts_for_day
] ->
{:ok, begin_datetime, _} = DateTime.from_iso8601(begin_time)
{:ok, end_datetime, _} = DateTime.from_iso8601(end_time)
Expand All @@ -82,7 +83,8 @@ defmodule Mix.Tasks.Gen.Badges do
begin_badge: begin_badge_datetime,
end_badge: end_badge_datetime,
type: String.to_integer(type),
tokens: String.to_integer(tokens)
tokens: String.to_integer(tokens),
counts_for_day: String.to_integer(counts_for_day) != 0
},
%{
avatar: get_avatar(image_path)
Expand Down
2 changes: 2 additions & 0 deletions lib/safira/contest/badge.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ defmodule Safira.Contest.Badge do
field(:type, :integer)
field(:tokens, :integer)

field(:counts_for_day, :boolean, default: true)

has_many(:referrals, Referral)
many_to_many(:attendees, Attendee, join_through: Redeem)

Expand Down
3 changes: 2 additions & 1 deletion lib/safira/contest/contest.ex
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,8 @@ defmodule Safira.Contest do
join: t in DailyToken,
on: a.id == t.attendee_id,
where:
not is_nil(a.user_id) and fragment("?::date", r.inserted_at) == ^date and b.type != ^0 and
not is_nil(a.user_id) and fragment("?::date", r.inserted_at) == ^date and
b.counts_for_day and
fragment("?::date", t.day) == ^date,
select: %{attendee: a, token_count: t.quantity},
preload: [badges: b, daily_tokens: t]
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
defmodule Safira.Repo.Migrations.AddCountsForDayToBadges do
use Ecto.Migration

def change do
alter table(:badges) do
add :counts_for_day, :boolean, default: true
end
end
end

0 comments on commit 28e20fa

Please sign in to comment.