module Roqua module CoreApi # @api private class CreateDossier < Base model :session, class: Sessions::AuthSession string :dossier_group_id model :dossier, class: Models::Dossier, default: nil model :person, class: Models::Person, default: nil def execute response = session.post "/dossier_groups/#{dossier_group_id}/dossiers", person: person_attributes, dossier: dossier_attributes if response.code == 422 errors_to_object(response, person) errors_to_object(response, dossier) end Models::Dossier.new(response) end private def dossier_attributes return {} unless dossier dossier.serializable_hash(except: :people).keep_if { |_k, v| !v.nil? } end def person_attributes return {} unless person person.serializable_hash.keep_if { |_k, v| !v.nil? } end end end end