mirror of
https://github.com/internetee/registry.git
synced 2025-08-04 17:01:44 +02:00
Basic contact check command implementation
This commit is contained in:
parent
65bb5166cc
commit
1f29925004
6 changed files with 106 additions and 0 deletions
|
@ -14,4 +14,22 @@ class Contact < ActiveRecord::Base
|
|||
code = Isikukood.new(ident)
|
||||
errors.add(:ident, 'bad format') unless code.valid?
|
||||
end
|
||||
|
||||
class << self
|
||||
def check_availability(codes)
|
||||
codes = [codes] if codes.is_a?(String)
|
||||
|
||||
res = []
|
||||
codes.each do |x|
|
||||
if Contact.find_by(code: x)
|
||||
res << {code: x, avail: 0, reason: 'in use'}
|
||||
else
|
||||
res << {code: x, avail: 1}
|
||||
end
|
||||
end
|
||||
|
||||
res
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue