WIP
parent
3aa39860d5
commit
bcf913991f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue