Skip to content

Commit

Permalink
Fix the logic for issuing promo codes for submitted twitter handles (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
IvanIvanoff authored Nov 20, 2023
1 parent 6077673 commit 9e2367c
Showing 1 changed file with 10 additions and 9 deletions.
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

0 comments on commit 9e2367c

Please sign in to comment.