Use contact serializer

Closes #1090
This commit is contained in:
Artur Beljajev 2019-03-01 12:15:50 +02:00
parent 1eb13341a7
commit 4d0117431c
3 changed files with 56 additions and 35 deletions

View file

@ -19,19 +19,15 @@ module Api
end
contacts = current_user_contacts.limit(limit).offset(offset)
serialized_contacts = contacts.map do |item|
serializer = Serializers::RegistrantApi::Contact.new(item)
serializer.to_json
end
serialized_contacts = contacts.collect { |contact| serialize_contact(contact) }
render json: serialized_contacts
end
def show
@contact = current_user_contacts.find_by(uuid: params[:uuid])
contact = current_user_contacts.find_by(uuid: params[:uuid])
if @contact
render json: @contact
if contact
render json: serialize_contact(contact)
else
render json: { errors: [{ base: ['Contact not found'] }] }, status: :not_found
end
@ -89,8 +85,7 @@ module Api
contact.registrar.notify(action)
end
serializer = Serializers::RegistrantApi::Contact.new(contact)
render json: serializer.to_json
render json: serialize_contact(contact)
end
private
@ -100,6 +95,10 @@ module Api
rescue CompanyRegister::NotAvailableError
current_registrant_user.direct_contacts
end
def serialize_contact(contact)
Serializers::RegistrantApi::Contact.new(contact).to_json
end
end
end
end