From e51ba79d888761d80d27c53eb3ba3886adc5c3f6 Mon Sep 17 00:00:00 2001 From: f Date: Wed, 9 Mar 2022 15:01:18 -0300 Subject: [PATCH] deprecar timestamp en sensores --- app/controllers/readings_controller.rb | 8 ++++---- app/models/sensor.rb | 2 +- db/migrate/20220309175041_remove_timestamp_from_sensor.rb | 7 +++++++ 3 files changed, 12 insertions(+), 5 deletions(-) create mode 100644 db/migrate/20220309175041_remove_timestamp_from_sensor.rb diff --git a/app/controllers/readings_controller.rb b/app/controllers/readings_controller.rb index 8231af7..8e1b877 100644 --- a/app/controllers/readings_controller.rb +++ b/app/controllers/readings_controller.rb @@ -50,16 +50,16 @@ class ReadingsController < ActionController::API :battery_status, :sample, :signature, - coordinates: %i[lat lng]) + coordinates: %i[lat lng]).tap do |p| + p[:timestamp] = Time.at p[:timestamp] + rescue TypeError + end end # Procesa los parĂ¡metros de un sensor def sensor_params(sensor) sensor.permit(:timestamp, :type, :value, :unit, :error).tap do |p| p[:local_type] = p.delete :type - p[:timestamp] = Time.at p[:timestamp] - rescue TypeError end end end - diff --git a/app/models/sensor.rb b/app/models/sensor.rb index 69b2bf8..edd6f11 100644 --- a/app/models/sensor.rb +++ b/app/models/sensor.rb @@ -3,5 +3,5 @@ class Sensor < ApplicationRecord belongs_to :arduino - validates_presence_of :timestamp, :local_type, :value, :unit + validates_presence_of :local_type, :value, :unit end diff --git a/db/migrate/20220309175041_remove_timestamp_from_sensor.rb b/db/migrate/20220309175041_remove_timestamp_from_sensor.rb new file mode 100644 index 0000000..2904c30 --- /dev/null +++ b/db/migrate/20220309175041_remove_timestamp_from_sensor.rb @@ -0,0 +1,7 @@ +# frozen_string_literal: true + +class RemoveTimestampFromSensor < ActiveRecord::Migration[6.1] + def change + remove_column :sensors, :timestamp, :datetime + end +end