Last active
February 2, 2022 17:12
-
-
Save Luiyit/1d3ba1ffdb4a976783c42597f9782147 to your computer and use it in GitHub Desktop.
Add pass customers to program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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