Skip to content

Instantly share code, notes, and snippets.

@Luiyit
Last active February 2, 2022 17:12
Show Gist options
  • Save Luiyit/1d3ba1ffdb4a976783c42597f9782147 to your computer and use it in GitHub Desktop.
Save Luiyit/1d3ba1ffdb4a976783c42597f9782147 to your computer and use it in GitHub Desktop.
Add pass customers to program
def add_pass_customers_to_program(passes_slugs, program_uid, include_cancelled: true)
ActiveRecord::Base.transaction do
passes_slugs.each do |slug|
pass = Pass.find_by_slug(slug)
pass_customers = pass.pass_customers.active_upcoming
pass_customers = pass_customers.not_cancelled unless include_cancelled
pass_customers.each do |pass_customer|
client = pass_customer.user
program_customer = ::Customers::Bundles::Program.active_upcoming.find_by(product_uid: program_uid, user_uuid: client.uuid)
next if program_customer
Customers::Bundles::Program.create!(
product_uid: program_uid,
user_uuid: client.uuid,
start_time: pass_customer.start_date,
finish_time: pass_customer.finish_date
)
Rails.logger.info("Program created for pass customer id: #{pass_customer.id}")
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment