guardar todo
All checks were successful
ci/woodpecker/push/woodpecker Pipeline was successful

cuando el arduino ya está creado no se guardan los sensores
This commit is contained in:
f 2022-09-06 16:17:00 -03:00
parent 3ac7755ab6
commit d147a8ad9e

View file

@ -21,14 +21,14 @@ class ReadingsController < ActionController::API
params[:arduinos]&.reject do |a|
a[:id].blank? || a[:sensores].empty?
end&.each do |a|
arduino = raspberry.arduinos.find_or_initialize_by(local_id: a[:id])
arduino = raspberry.arduinos.find_or_create_by(local_id: a[:id])
a[:sensores].each do |s|
arduino.sensors.build(reading: reading, **sensor_params(s))
arduino.sensors.create(reading: reading, **sensor_params(s))
end
end
if raspberry.save
if raspberry.save!
render plain: reading.id, status: :ok
else
head :bad_request
@ -36,6 +36,8 @@ class ReadingsController < ActionController::API
end
rescue ActiveRecord::RecordNotUnique
render plain: params[:transaction_uuid], status: :ok
rescue ActiveRecord::RecordInvalid
head :bad_request
end
private