Class: ForestAdminAgent::Routes::Resources::Update
- Inherits:
-
AbstractAuthenticatedRoute
- Object
- AbstractRoute
- AbstractAuthenticatedRoute
- ForestAdminAgent::Routes::Resources::Update
- Includes:
- Builder, ForestAdminDatasourceToolkit::Components::Query
- Defined in:
- lib/forest_admin_agent/routes/resources/update.rb
Instance Method Summary collapse
Methods inherited from AbstractAuthenticatedRoute
#build, #format_attributes, #redacted_full_projection, #redacted_projection_with_pks
Methods inherited from AbstractRoute
#add_route, #build, #initialize, #routes
Constructor Details
This class inherits a constructor from ForestAdminAgent::Routes::AbstractRoute
Instance Method Details
#handle_request(args = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'lib/forest_admin_agent/routes/resources/update.rb', line 17 def handle_request(args = {}) context = build(args) context..can?(:edit, context.collection) scope = context..get_scope(context.collection) primary_key_values = Utils::Id.unpack_id(context.collection, args[:params]['id'], with_key: true) condition_tree = ConditionTree::ConditionTreeFactory.match_records(context.collection, [primary_key_values]) filter = ForestAdminDatasourceToolkit::Components::Query::Filter.new( condition_tree: ConditionTree::ConditionTreeFactory.intersect([condition_tree, scope]) ) drop_relationships!(args) data = format_attributes(args, context.collection) context.collection.update(context.caller, filter, data) projection = redacted_full_projection(context) records = context.collection.list(context.caller, filter, projection) { name: args[:params]['collection_name'], content: JSONAPI::Serializer.serialize( records[0], is_collection: false, class_name: context.collection.name, serializer: Serializer::ForestSerializer ) } end |
#setup_routes ⇒ Object
11 12 13 14 15 |
# File 'lib/forest_admin_agent/routes/resources/update.rb', line 11 def setup_routes add_route('forest_update', 'put', '/:collection_name/:id', ->(args) { handle_request(args) }) self end |