Add Champ#for_api
This commit is contained in:
parent
083dfb4eaa
commit
866c74ce63
7 changed files with 25 additions and 21 deletions
|
@ -47,6 +47,10 @@ class Champ < ApplicationRecord
|
|||
value.presence
|
||||
end
|
||||
|
||||
def for_api
|
||||
value
|
||||
end
|
||||
|
||||
def main_value_name
|
||||
:value
|
||||
end
|
||||
|
|
|
@ -88,4 +88,8 @@ class Champs::CarteChamp < Champ
|
|||
)
|
||||
end
|
||||
end
|
||||
|
||||
def for_api
|
||||
geo_json.present? ? geo_json.to_json : nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,4 +4,8 @@ class Champs::DecimalNumberChamp < Champ
|
|||
def for_export
|
||||
value.present? ? value.to_f : nil
|
||||
end
|
||||
|
||||
def for_api
|
||||
value.present? ? value.to_f : nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -4,4 +4,8 @@ class Champs::IntegerNumberChamp < Champ
|
|||
def for_export
|
||||
value.present? ? value.to_i : nil
|
||||
end
|
||||
|
||||
def for_api
|
||||
value.present? ? value.to_i : nil
|
||||
end
|
||||
end
|
||||
|
|
|
@ -37,6 +37,10 @@ class Champs::LinkedDropDownListChamp < Champ
|
|||
value.present? ? "#{primary_value || ''};#{secondary_value || ''}" : nil
|
||||
end
|
||||
|
||||
def for_api
|
||||
value.present? ? { primary: primary_value, secondary: secondary_value } : nil
|
||||
end
|
||||
|
||||
def mandatory_and_blank?
|
||||
mandatory? && (primary_value.blank? || secondary_value.blank?)
|
||||
end
|
||||
|
|
|
@ -48,6 +48,10 @@ class Champs::PieceJustificativeChamp < Champ
|
|||
errors
|
||||
end
|
||||
|
||||
def for_api
|
||||
Rails.application.routes.url_helpers.url_for(piece_justificative_file)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def create_virus_scan
|
||||
|
|
|
@ -13,28 +13,8 @@ class ChampSerializer < ActiveModel::Serializer
|
|||
case object
|
||||
when GeoArea
|
||||
object.geometry
|
||||
when Champs::CarteChamp
|
||||
if object.geo_json.present?
|
||||
object.geo_json.to_json
|
||||
end
|
||||
when Champs::DecimalNumberChamp
|
||||
if object.value.present?
|
||||
object.value.to_f
|
||||
end
|
||||
when Champs::IntegerNumberChamp
|
||||
if object.value.present?
|
||||
object.value.to_i
|
||||
end
|
||||
when Champs::LinkedDropDownListChamp
|
||||
if object.value.present?
|
||||
{ primary: object.primary_value, secondary: object.secondary_value }
|
||||
end
|
||||
when Champs::PieceJustificativeChamp
|
||||
if object.piece_justificative_file.attached?
|
||||
url_for(object.piece_justificative_file)
|
||||
end
|
||||
else
|
||||
object.value
|
||||
object.for_api
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue