Skip to content

Instantly share code, notes, and snippets.

@Luiyit
Last active November 20, 2020 19:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Luiyit/b3335e94ff1ea79a4f7de68293001d14 to your computer and use it in GitHub Desktop.
Save Luiyit/b3335e94ff1ea79a4f7de68293001d14 to your computer and use it in GitHub Desktop.
Remove the class record and customer. Be carefull about the source of the class customer (pass, pack, paid)
def remove_class(class_id, remove)
klass = TalentClass.find(class_id)
amount_class_customers_removed = 0
if klass
zoon_meeting = ZoomMeeting.find_by(talent_class_id: class_id)
if remove
ActiveRecord::Base.transaction do
zoon_meeting.delete if zoon_meeting
TalentClassSkill.where(talent_class_id: class_id).delete_all
amount_class_customers_removed = TalentClassCustomer.where(talent_class_id: class_id).delete_all
klass.delete
rescue ActiveRecord::RecordNotFound, ActiveRecord::RecordNotDestroyed => ex
return { errors: ex.message, removed: false }
end
end
end
return {klass: klass, amount_class_customers_removed: amount_class_customers_removed, removed: remove }
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment