diff --git a/lib/amorail/entity/params.rb b/lib/amorail/entity/params.rb index 2de76e7..26433ff 100644 --- a/lib/amorail/entity/params.rb +++ b/lib/amorail/entity/params.rb @@ -1,4 +1,7 @@ module Amorail # :nodoc: all + + MULTISELECT_FIELD_TYPE = '5' + class Entity def params data = {} @@ -17,11 +20,10 @@ def custom_fields props = properties.send(self.class.amo_name) custom_fields = [] - - self.class.properties.each do |k, v| + self.class.properties.each do |k, value| prop_id = props.send(k).id - prop_val = { value: send(k) }.merge(v) - custom_fields << { id: prop_id, values: [prop_val] } + prop_val = props.send(k)['type_id'] == MULTISELECT_FIELD_TYPE ? [send(k)] : { value: send(k) }.merge(value) + custom_fields << { id: prop_id, values: [prop_val].flatten } end custom_fields @@ -41,7 +43,10 @@ def create_params(method) def normalize_custom_fields(val) val.reject do |field| - field[:values].all? { |item| !item[:value] } + next if field[:values].instance_of? Array + field[:values].all? { |item| + !item[:value] + } end end