Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- User.distinct.includes(:contracts).joins(:contracts, :user_reward_tier).where(query).each do |user|
- earliest_non_cancelled = user.contracts.where("state != 'cancelled'").order(created_at: :asc)[0]
- if earliest_non_cancelled
- next if earliest_non_cancelled.created_at < cut_off_date
- end
- # This guy already got his points
- next if user.id == 223062
- Rails.logger.warn "Adding RewardPoint Grant for User #{user.id}"
- # Add points for them via reward grant, reason: 'Summer Rewards Promo'
- RewardPromo::OneTimePointBoost.new(user.user_reward_tier).call
- end
- cut_off_date = Date.new(2018,05,23)
- # This will get all users who had reward tiers before the 23rd, and also had cancelled contracts before 5/23
- query = "user_reward_tiers.created_at < '2018/05/23' and contracts.created_at < '2018/05/23' and contracts.state = 'cancelled'"
Add Comment
Please, Sign In to add comment