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
|
value.presence
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def for_api
|
||||||
|
value
|
||||||
|
end
|
||||||
|
|
||||||
def main_value_name
|
def main_value_name
|
||||||
:value
|
:value
|
||||||
end
|
end
|
||||||
|
|
|
@ -88,4 +88,8 @@ class Champs::CarteChamp < Champ
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def for_api
|
||||||
|
geo_json.present? ? geo_json.to_json : nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,4 +4,8 @@ class Champs::DecimalNumberChamp < Champ
|
||||||
def for_export
|
def for_export
|
||||||
value.present? ? value.to_f : nil
|
value.present? ? value.to_f : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def for_api
|
||||||
|
value.present? ? value.to_f : nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -4,4 +4,8 @@ class Champs::IntegerNumberChamp < Champ
|
||||||
def for_export
|
def for_export
|
||||||
value.present? ? value.to_i : nil
|
value.present? ? value.to_i : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def for_api
|
||||||
|
value.present? ? value.to_i : nil
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -37,6 +37,10 @@ class Champs::LinkedDropDownListChamp < Champ
|
||||||
value.present? ? "#{primary_value || ''};#{secondary_value || ''}" : nil
|
value.present? ? "#{primary_value || ''};#{secondary_value || ''}" : nil
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def for_api
|
||||||
|
value.present? ? { primary: primary_value, secondary: secondary_value } : nil
|
||||||
|
end
|
||||||
|
|
||||||
def mandatory_and_blank?
|
def mandatory_and_blank?
|
||||||
mandatory? && (primary_value.blank? || secondary_value.blank?)
|
mandatory? && (primary_value.blank? || secondary_value.blank?)
|
||||||
end
|
end
|
||||||
|
|
|
@ -48,6 +48,10 @@ class Champs::PieceJustificativeChamp < Champ
|
||||||
errors
|
errors
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def for_api
|
||||||
|
Rails.application.routes.url_helpers.url_for(piece_justificative_file)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def create_virus_scan
|
def create_virus_scan
|
||||||
|
|
|
@ -13,28 +13,8 @@ class ChampSerializer < ActiveModel::Serializer
|
||||||
case object
|
case object
|
||||||
when GeoArea
|
when GeoArea
|
||||||
object.geometry
|
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
|
else
|
||||||
object.value
|
object.for_api
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue