Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Give Reward Points to Users

Gist URL: https://gist.github.com/fhyfirman/17c7c57a80b6adf9dfa7ea622b05d608 Script

# How to run the command: rails runner give_reward_points.rb
#
# Example:
# rows = [
#   'user_id, points_total, description',
# ]
#
rows = [
  '817882, 110, CNY Promo 2024 - Booking ID 4127737 ',
  '465633, 110, CNY Promo 2024 - Booking ID 4149207',
]

rows.each do |row|
  user_id, points, description = row.split(',').map(&:strip)

  user_id = user_id.to_i
  points = points.to_i

  reward = Reward.new user_id: user_id,
                      expiry_date: Date.today + 10.years,
                      points_total: points,
                      points_pending: 0,
                      description: description,
                      redeemed: false
  reward.save!

  # Print the result
  result_ids = Reward.where(description: description).pluck(:id, :description)
  puts result_ids
end