Add basic contact update functionality to REPP

This commit is contained in:
Karl Erik Õunapuu 2020-10-06 16:02:13 +03:00
parent f72ec0ec3a
commit d4628d52ba
No known key found for this signature in database
GPG key ID: C9DD647298A34764

View file

@ -31,7 +31,7 @@ module Repp
}
end
desc 'Create new contact object'
desc 'Creates a new contact object'
params do
requires :contact, type: Hash, allow_blank: false do
requires :name, type: String, desc: 'Full name of contact'
@ -41,10 +41,14 @@ module Repp
requires :country_code, type: String, desc: 'Address country'
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 :fax, type: String, desc: 'Fax number of contact'
requires :street, type: String, desc: 'Address street'
requires :city, type: String, desc: 'Address city'
requires :zip, type: String, desc: 'Address ZIP'
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
@ -55,7 +59,49 @@ module Repp
action = Actions::ContactCreate.new(@contact, @legal_doc)
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
status :bad_request
@response = { errors: @contact.errors }