envolver todo en una transacción
This commit is contained in:
parent
cf4dfa3aad
commit
8de7a8a74c
1 changed files with 15 additions and 13 deletions
|
@ -6,23 +6,25 @@ class ReadingsController < ActionController::API
|
|||
|
||||
# @see {https://docutopia.tupale.co/sutty:nodemecu:api}
|
||||
def create
|
||||
reading = raspberry.readings.build reading_params
|
||||
reading.id = params[:transaction_uuid]
|
||||
# TODO: Verificar firma
|
||||
reading.signature = headers[:'X-Signature']
|
||||
Reading.transaction do
|
||||
reading = raspberry.readings.build reading_params
|
||||
reading.id = params[:transaction_uuid]
|
||||
# TODO: Verificar firma
|
||||
reading.signature = headers[:'X-Signature']
|
||||
|
||||
params[:arduinos]&.each do |a|
|
||||
arduino = reading.arduinos.build local_id: a[:id], raspberry: raspberry
|
||||
params[:arduinos]&.each do |a|
|
||||
arduino = reading.arduinos.build local_id: a[:id], raspberry: raspberry
|
||||
|
||||
a[:sensores]&.each do |s|
|
||||
arduino.sensors.build(sensor_params s)
|
||||
a[:sensores]&.each do |s|
|
||||
arduino.sensors.build(sensor_params s)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
if reading.save
|
||||
render plain: reading.uuid, status: :ok
|
||||
else
|
||||
head :bad_request
|
||||
if reading.save
|
||||
render plain: reading.id, status: :ok
|
||||
else
|
||||
head :bad_request
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue