app/controllers/iro/datapoints_controller.rb in iron_warbler-2.0.7.10 vs app/controllers/iro/datapoints_controller.rb in iron_warbler-2.0.7.11
- old
+ new
@@ -1,15 +1,20 @@
class Iro::DatapointsController < Iro::ApplicationController
## params: d, k, v
def create
+ authorize! :create, Iro::Datapoint
begin
- Iro::Datapoint.create( k: params[:k], v: params[:v], created_at: params[:time] )
+ Iro::Datapoint.create!(
+ date: params[:d],
+ kind: params[:k],
+ value: params[:v],
+ )
render json: { status: :ok }
- rescue ActiveRecord::NotNullViolation => exception
- render json: { status: :unauthorized }, status: :unauthorized
+ rescue Mongoid::Errors::Validations => e
+ render json: { status: 401 }, status: 401
end
end
def index
# from = '2023-12-20'
@@ -22,11 +27,11 @@
iro_datapoints as dps
RIGHT JOIN dates d ON d.date = dps.d WHERE d.date BETWEEN '2023-12-01' AND '2023-12-31'
ORDER BY
d.date;"
- outs = ActiveRecord::Base.connection.execute(sql)
- puts! outs, 'outs'
+ # outs = ActiveRecord::Base.connection.execute(sql)
+ # puts! outs, 'outs'
render json: outs
end