pull/815/head
Rick Carlino 2018-04-27 11:49:59 -05:00
parent 3aa39860d5
commit bcf913991f
2 changed files with 31 additions and 23 deletions

View File

@ -25,7 +25,13 @@ module Api
end
def dump
mutate Devices::Dump.run(device: current_device)
raise "Need to write tests for this and `dump_status`"
Devices::Dump.run_by_id(current_device.id)
render json: {ok: "OK"}
end
def dump_status
raise "Need a way to check the status of the job."
end
end
end

View File

@ -1,33 +1,35 @@
module Devices
# DO NOT USE THIS IN YOUR APPLICATION! = = = = = =
# Download all your account data as a single JSON document. Used by the dev
# team to debug data related issues (especially those that are specific to a
# particular server or database).
# DO NOT USE THIS IN YOUR APPLICATION! = = = = = =
class Dump < Mutations::Command
RESOURCES = [
Pair[:images, ImageSerializer],
Pair[:regimens, RegimenSerializer],
Pair[:peripherals, PeripheralSerializer],
# Pair[:sequences, SequenceSerializer],
Pair[:farm_events, FarmEventSerializer],
# Pair[:tools, ToolSerializer],
# Pair[:points, PointSerializer],
Pair[:users, UserSerializer],
Pair[:webcam_feeds, WebcamFeedSerializer]
]
RESOURCES = {
farm_events: FarmEventSerializer,
images: ImageSerializer,
peripherals: PeripheralSerializer,
points: PointSerializer,
regimens: RegimenSerializer,
sequences: SequenceSerializer,
tools: ToolSerializer,
users: UserSerializer,
webcam_feeds: WebcamFeedSerialize
}
required do
model :device, class: Device
def self.run_by_id(id)
Devices::Dump.delay.run(device_id: current_device)
end
required { model :device_id, class: number }
def execute
output = { device: DeviceSerializer.new(device).as_json }
RESOURCES.map do |pair|
list = device.send(pair.head)
output[pair.head] = list.map { |x| pair.tail.new(x).as_json }
RESOURCES.map do |(name, serializer)|
list = device.send(name)
output[name] = list.map { |x| serializer.new(x).as_json }
end
output
end
end
private
def device
@device ||= Device.find(device_id)
end
end