Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: cv cron-job #390

Merged
merged 1 commit into from
Feb 5, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 39 additions & 0 deletions lib/safira/jobs/cv_badge.ex
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
defmodule Safira.Jobs.CVBadge do
@moduledoc """
Job to gift the CV badge to all eligible attendees.
Eligible attendees are those that have uploaded their CV.

Receives the badge_id to gift.
"""
import Ecto.Query, warn: false

alias Safira.Accounts.Attendee
alias Safira.Contest
alias Safira.Contest.Badge
alias Safira.Repo

@spec run(integer()) :: :ok
def run(badge_id) do
badge = Repo.get(Badge, badge_id)

list_eligible_attendees()
|> Enum.each(&create_redeem(&1, badge))
end

defp list_eligible_attendees do
Attendee
|> where([a], not is_nil(a.cv))
|> Repo.all()
end

defp create_redeem(attendee, badge) do
Contest.create_redeem(
%{
attendee_id: attendee.id,
staff_id: 1,
badge_id: badge.id
},
:admin
)
end
end
Loading