You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
774 B

  1. # frozen_string_literal: true
  2. class Form::PreviewCardProviderBatch
  3. include ActiveModel::Model
  4. include Authorization
  5. attr_accessor :preview_card_provider_ids, :action, :current_account
  6. def save
  7. case action
  8. when 'approve'
  9. approve!
  10. when 'reject'
  11. reject!
  12. end
  13. end
  14. private
  15. def preview_card_providers
  16. PreviewCardProvider.where(id: preview_card_provider_ids)
  17. end
  18. def approve!
  19. preview_card_providers.each { |provider| authorize(provider, :update?) }
  20. preview_card_providers.update_all(trendable: true, reviewed_at: Time.now.utc)
  21. end
  22. def reject!
  23. preview_card_providers.each { |provider| authorize(provider, :update?) }
  24. preview_card_providers.update_all(trendable: false, reviewed_at: Time.now.utc)
  25. end
  26. end