FarmBot/Farmbot-Web-App

View on GitHub
app/serializers/sensor_reading_serializer.rb

Summary

Maintainability
A
0 mins
Test Coverage
class SensorReadingSerializer < ApplicationSerializer
  attributes :mode, :pin, :value, :x, :y, :z, :read_at
  # This is for legacy support reasons.
  # Very old sensor_readings will have a
  # read_at value of `nil`, so we pre-populate it
  # to `created_at` for the convenience of API users.
  def read_at
    object.read_at || object.created_at
  end
end