Integrate auction

Closes #874
This commit is contained in:
Artur Beljajev 2018-11-29 15:08:22 +02:00
parent 640faaadb9
commit 42e8f86dae
51 changed files with 1619 additions and 53 deletions

View file

@ -6,8 +6,16 @@ module DNS
@name = name
end
def available?
!unavailable?
end
def available_with_code?(code)
pending_auction.domain_registrable?(code)
end
def unavailable?
registered? || blocked? || zone_with_same_origin?
at_auction? || awaiting_payment? || registered? || blocked? || zone_with_same_origin?
end
def unavailability_reason
@ -17,9 +25,38 @@ module DNS
:blocked
elsif zone_with_same_origin?
:zone_with_same_origin
elsif at_auction?
:at_auction
elsif awaiting_payment?
:awaiting_payment
end
end
def sell_at_auction
Auction.sell(self)
update_whois
end
def at_auction?
pending_auction&.started?
end
def awaiting_payment?
pending_auction&.awaiting_payment?
end
def pending_registration?
pending_auction&.payment_received?
end
def update_whois
Whois::Record.refresh(self)
end
def to_s
name
end
private
attr_reader :name
@ -35,5 +72,9 @@ module DNS
def zone_with_same_origin?
DNS::Zone.where(origin: name).any?
end
def pending_auction
Auction.pending(self)
end
end
end