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

Fix the logic for issuing promo codes for submitted twitter handles #3988

Merged
merged 1 commit into from
Nov 20, 2023
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
19 changes: 10 additions & 9 deletions lib/sanbase/monitored_twitter_handle/monitored_twitter_handle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -128,20 +128,21 @@ defmodule Sanbase.MonitoredTwitterHandle do
# This includes all used and unused promo codes for that campaign.
codes_count = length(codes)

cond do
records_count >= 7 and codes_count <= 1 ->
create_user_promo_code(user_id, 27)

records_count >= 3 and codes_count == 0 ->
create_user_promo_code(user_id, 54)
# Run the creation in 2 ifs so in case of re-issuing of promo codes,
# we create all the necessary promo codes on one run
if records_count >= 3 and codes_count == 0 do
create_user_promo_code_for_campaign(user_id, 27)
end

true ->
:ok
if records_count >= 7 and codes_count == 1 do
create_user_promo_code_for_campaign(user_id, 54)
end

:ok
end
end

defp create_user_promo_code(user_id, percent_off) do
defp create_user_promo_code_for_campaign(user_id, percent_off) do
redeem_by = DateTime.utc_now() |> DateTime.add(30, :day) |> DateTime.truncate(:second)

{:ok, coupon} =
Expand Down