mirror of
https://github.com/internetee/registry.git
synced 2025-06-11 23:24:48 +02:00
Add basic contact update functionality to REPP
This commit is contained in:
parent
f72ec0ec3a
commit
d4628d52ba
1 changed files with 52 additions and 6 deletions
|
@ -31,7 +31,7 @@ module Repp
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
desc 'Create new contact object'
|
desc 'Creates a new contact object'
|
||||||
params do
|
params do
|
||||||
requires :contact, type: Hash, allow_blank: false do
|
requires :contact, type: Hash, allow_blank: false do
|
||||||
requires :name, type: String, desc: 'Full name of contact'
|
requires :name, type: String, desc: 'Full name of contact'
|
||||||
|
@ -41,10 +41,14 @@ module Repp
|
||||||
requires :country_code, type: String, desc: 'Address country'
|
requires :country_code, type: String, desc: 'Address country'
|
||||||
requires :phone, type: String, desc: 'Phone number of contact. In format of +country_prefix.number'
|
requires :phone, type: String, desc: 'Phone number of contact. In format of +country_prefix.number'
|
||||||
requires :email, type: String, desc: 'Email address of contact'
|
requires :email, type: String, desc: 'Email address of contact'
|
||||||
requires :fax, type: String, desc: 'Fax number of contact'
|
optional :fax, type: String, desc: 'Fax number of contact'
|
||||||
requires :street, type: String, desc: 'Address street'
|
optional :street, type: String, desc: 'Address street'
|
||||||
requires :city, type: String, desc: 'Address city'
|
optional :city, type: String, desc: 'Address city'
|
||||||
requires :zip, type: String, desc: 'Address ZIP'
|
optional :zip, type: String, desc: 'Address ZIP'
|
||||||
|
end
|
||||||
|
optional :legal_document, type: Hash, allow_blank: false do
|
||||||
|
requires :body, type: String, desc: 'Raw data of legal document'
|
||||||
|
requires :type, type: String, desc: 'Format of legal document'
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,7 +59,49 @@ module Repp
|
||||||
action = Actions::ContactCreate.new(@contact, @legal_doc)
|
action = Actions::ContactCreate.new(@contact, @legal_doc)
|
||||||
|
|
||||||
if action.call
|
if action.call
|
||||||
@response = { data: { contact: { id: @contact.id } } }
|
@response = { contact: { id: @contact.code } }
|
||||||
|
else
|
||||||
|
status :bad_request
|
||||||
|
@response = { errors: @contact.errors }
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
desc 'Update contact properties'
|
||||||
|
params do
|
||||||
|
requires :contact, type: Hash, allow_blank: false do
|
||||||
|
optional :ident, type: Hash, allow_blank: false do
|
||||||
|
requires :ident, type: String, desc: 'Government identifier of contact'
|
||||||
|
requires :ident_type, type: String, desc: 'Type of contact ident'
|
||||||
|
requires :ident_country_code, type: String, desc: 'Ident country code'
|
||||||
|
end
|
||||||
|
optional :name, type: String, desc: 'Full name of contact'
|
||||||
|
optional :country_code, type: String, desc: 'Address country'
|
||||||
|
optional :phone, type: String, desc: 'Phone number of contact. In format of +country_prefix.number'
|
||||||
|
optional :email, type: String, desc: 'Email address of contact'
|
||||||
|
optional :fax, type: String, desc: 'Fax number of contact'
|
||||||
|
optional :street, type: String, desc: 'Address street'
|
||||||
|
optional :city, type: String, desc: 'Address city'
|
||||||
|
optional :zip, type: String, desc: 'Address ZIP'
|
||||||
|
end
|
||||||
|
optional :legal_document, type: Hash, allow_blank: false do
|
||||||
|
requires :body, type: String, desc: 'Raw data of legal document'
|
||||||
|
requires :type, type: String, desc: 'Format of legal document'
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
post '/:code' do
|
||||||
|
@contact = current_user.registrar.contacts.find_by(code: params[:code])
|
||||||
|
(status(:not_found) && return) unless @contact
|
||||||
|
|
||||||
|
@new_params = params[:contact]
|
||||||
|
@legal_doc = params[:legal_document]
|
||||||
|
@ident = params[:contact][:ident] || {}
|
||||||
|
|
||||||
|
action = Actions::ContactUpdate.new(@contact, @new_params,
|
||||||
|
@legal_doc, @ident, current_user)
|
||||||
|
|
||||||
|
if action.call
|
||||||
|
@response = {}
|
||||||
else
|
else
|
||||||
status :bad_request
|
status :bad_request
|
||||||
@response = { errors: @contact.errors }
|
@response = { errors: @contact.errors }
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue