From d4628d52baff1c0b4f3fc68ad00fe9387b803582 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karl=20Erik=20=C3=95unapuu?= Date: Tue, 6 Oct 2020 16:02:13 +0300 Subject: [PATCH] Add basic contact update functionality to REPP --- app/api/repp/contact_v1.rb | 58 ++++++++++++++++++++++++++++++++++---- 1 file changed, 52 insertions(+), 6 deletions(-) diff --git a/app/api/repp/contact_v1.rb b/app/api/repp/contact_v1.rb index 1eb5a88ce..cdcc3ff6f 100644 --- a/app/api/repp/contact_v1.rb +++ b/app/api/repp/contact_v1.rb @@ -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 }