preview_card_provider_batch.rb 776 B

123456789101112131415161718192021222324252627282930313233
  1. # frozen_string_literal: true
  2. class Trends::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, :review?) }
  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, :review?) }
  24. preview_card_providers.update_all(trendable: false, reviewed_at: Time.now.utc)
  25. end
  26. end