block_domain_service.rb 354 Bytes
Newer Older
1
2
# frozen_string_literal: true

Eugen Rochko's avatar
Eugen Rochko committed
3
4
class BlockDomainService < BaseService
  def call(domain)
Eugen Rochko's avatar
Eugen Rochko committed
5
    DomainBlock.find_or_create_by!(domain: domain)
Eugen Rochko's avatar
Eugen Rochko committed
6
7
8

    Account.where(domain: domain).find_each do |account|
      if account.subscribed?
9
        account.subscription(api_subscription_url(account.id)).unsubscribe
Eugen Rochko's avatar
Eugen Rochko committed
10
11
12
13
14
15
      end

      account.destroy!
    end
  end
end