Merge branch 'saved_gardens_ii' into garden_snapshot_i

pull/801/head
Rick Carlino 2018-04-19 15:50:30 -05:00
commit 4f6636eed0
5 changed files with 39 additions and 17 deletions

View File

@ -10,7 +10,7 @@ module Api
def update
mutate Configs::Update
.run(target_klass: config_object, update_attrs: raw_json)
.run(target: config_object, update_attrs: raw_json)
end
def destroy

View File

@ -1,17 +1,25 @@
module Configs
class Update < Mutations::Command
HOTFIX = [ :encoder_scaling_x, :encoder_scaling_y, :encoder_scaling_z ]
BAD = 56
GOOD = 5556
required do
duck :target_klass, methods: [:update_attributes!]
duck :target, methods: [:update_attributes!]
duck :update_attrs, methods: [:deep_symbolize_keys]
end
def execute
target_klass.update_attributes!(sliced_attrs)
target_klass
target.assign_attributes(sliced_attrs)
HOTFIX.map do |attr|
target.assign_attributes(attr => GOOD) if target.try(attr) == BAD
end
target.save!
target
end
def sliced_attrs
whitelist = target_klass.class.column_names.map(&:to_sym)
whitelist = target.class.column_names.map(&:to_sym)
updates = update_attrs
.deep_symbolize_keys
.except(:device_id, :id, :created_at)

View File

@ -51,16 +51,16 @@ FarmBot::Application.routes.draw do
# Make life easier on API users by not adding special rules for singular
# resources.
# Might be safe to remove now with the advent of TaggedResource.kind
get "/device/:id" => "devices#show", as: :get_device_redirect
get "/export_data" => "devices#dump", as: :dump_device
get "/storage_auth" => "images#storage_auth", as: :storage_auth
patch "/device/:id" => "devices#update", as: :patch_device_redirect
patch "/users/:id" => "users#update", as: :patch_users_redirect
patch "/webcam_feed/:id" => "webcam_feeds#update", as: :patch_webcam_feed_redirect
put "/device/:id" => "devices#update", as: :put_device_redirect
put "/password_resets" => "password_resets#update", as: :whatever
put "/users/:id" => "users#update", as: :put_users_redirect
put "/webcam_feed/:id" => "webcam_feeds#update", as: :put_webcam_feed_redirect
get "/device/:id" => "devices#show", as: :get_device_redirect
get "/export_data" => "devices#dump", as: :dump_device
get "/storage_auth" => "images#storage_auth", as: :storage_auth
patch "/device/:id" => "devices#update", as: :patch_device_redirect
patch "/users/:id" => "users#update", as: :patch_users_redirect
patch "/webcam_feed/:id" => "webcam_feeds#update", as: :patch_webcam_feed_redirect
put "/device/:id" => "devices#update", as: :put_device_redirect
put "/password_resets" => "password_resets#update", as: :whatever
put "/users/:id" => "users#update", as: :put_users_redirect
put "/webcam_feed/:id" => "webcam_feeds#update", as: :put_webcam_feed_redirect
end
devise_for :users

View File

@ -0,0 +1,14 @@
class FiftySix < ActiveRecord::Migration[5.1]
BAD = 56
GOOD = 5556
ALL_OF_THEM = [ :encoder_scaling_x, :encoder_scaling_y, :encoder_scaling_z ]
def up
ALL_OF_THEM.map do |attr|
FirmwareConfig.where(attr => BAD).update_all(attr => GOOD)
end
end
def down
end
end

View File

@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20180418205557) do
ActiveRecord::Schema.define(version: 20180419164627) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@ -550,7 +550,7 @@ ActiveRecord::Schema.define(version: 20180418205557) do
SELECT sequences.id AS sequence_id,
( SELECT count(*) AS count
FROM edge_nodes
WHERE (((edge_nodes.kind)::text = 'sequence_id'::text) AND ((edge_nodes.value)::integer = sequences.id))) AS edge_node_count,
WHERE ((edge_nodes.sequence_id = sequences.id) AND ((edge_nodes.kind)::text = 'sequence_id'::text) AND ((edge_nodes.value)::text = (sequences.id)::text))) AS edge_node_count,
( SELECT count(*) AS count
FROM farm_events
WHERE ((farm_events.executable_id = sequences.id) AND ((farm_events.executable_type)::text = 'Sequence'::text))) AS farm_event_count,