mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
35 lines
833 B
Ruby
35 lines
833 B
Ruby
module Domains
|
|
module CheckBalance
|
|
class Mass < ActiveInteraction::Base
|
|
array :domains do
|
|
object class: Epp::Domain
|
|
end
|
|
string :operation
|
|
integer :period
|
|
string :unit
|
|
float :balance
|
|
|
|
attr_accessor :total_price
|
|
|
|
def execute
|
|
calculate_total_price
|
|
|
|
balance >= @total_price
|
|
end
|
|
|
|
def calculate_total_price
|
|
@total_price = 0
|
|
domains.each do |domain|
|
|
task = Domains::CheckBalance::SingleDomain.run(domain: domain, operation: 'renew',
|
|
period: period, unit: unit)
|
|
|
|
if task.valid?
|
|
@total_price += task.result
|
|
else
|
|
task.errors.each { |task_error| errors.import task_error }
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|
|
end
|