This commit is contained in:
parent
212524429f
commit
2e8a75e97e
2 changed files with 16 additions and 1 deletions
|
@ -12,7 +12,6 @@ class ReadingsController < ActionController::API
|
||||||
end
|
end
|
||||||
|
|
||||||
Reading.transaction do
|
Reading.transaction do
|
||||||
reading = raspberry.readings.build reading_params
|
|
||||||
reading.id = params[:transaction_uuid]
|
reading.id = params[:transaction_uuid]
|
||||||
reading.signature = request.headers[:'X-Signature']
|
reading.signature = request.headers[:'X-Signature']
|
||||||
reading.raw_transaction = request.raw_post
|
reading.raw_transaction = request.raw_post
|
||||||
|
@ -79,10 +78,20 @@ class ReadingsController < ActionController::API
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def reading
|
||||||
|
@reading ||= raspberry.readings.build reading_params
|
||||||
|
end
|
||||||
|
|
||||||
# Procesa los parámetros de un sensor
|
# Procesa los parámetros de un sensor
|
||||||
def sensor_params(sensor)
|
def sensor_params(sensor)
|
||||||
sensor.permit(:timestamp, :type, :value, :unit, :error).tap do |p|
|
sensor.permit(:timestamp, :type, :value, :unit, :error).tap do |p|
|
||||||
p[:local_type] = p.delete :type
|
p[:local_type] = p.delete :type
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def append_info_to_payload(payload)
|
||||||
|
super
|
||||||
|
|
||||||
|
payload[:errors] = reading.try(:errors).try(:full_messages)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -76,6 +76,12 @@ Rails.application.configure do
|
||||||
# Log Rage
|
# Log Rage
|
||||||
config.lograge.enabled = true
|
config.lograge.enabled = true
|
||||||
|
|
||||||
|
config.lograge.custom_options = lambda do |event|
|
||||||
|
next {} unless event.payload[:errors].present?
|
||||||
|
|
||||||
|
{ errors: event.payload[:errors].try(:join, ', ') }
|
||||||
|
end
|
||||||
|
|
||||||
# Use default logging formatter so that PID and timestamp are not suppressed.
|
# Use default logging formatter so that PID and timestamp are not suppressed.
|
||||||
config.log_formatter = ::Logger::Formatter.new
|
config.log_formatter = ::Logger::Formatter.new
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue