Class: Api::V2::WorkOrderResource

Inherits:
BaseResource
  • Object
show all
Defined in:
app/resources/api/v2/work_order_resource.rb

Overview

Class WorkOrderResource provides an abstraction of request for exposure to external applications. It is intended to allow us to update the internal representation, while maintaining an external interface

Constant Summary collapse

IGNORED_METADATA_FIELDS =
%w(id request_id created_at updated_at).freeze

Instance Method Summary collapse

Methods inherited from BaseResource

apply_includes, default_includes, inclusions, resolve_relationship_names_to_relations, updatable_fields

Instance Method Details

#optionsObject


60
61
62
63
64
# File 'app/resources/api/v2/work_order_resource.rb', line 60

def options
  _model.example_request..attributes.reject do |key, value|
    IGNORED_METADATA_FIELDS.include?(key) || value.blank?
  end
end

#order_typeObject


56
57
58
# File 'app/resources/api/v2/work_order_resource.rb', line 56

def order_type
  _model.work_order_type.name
end

#project_idObject

JSONAPI::Resource doesn't support has_one through relationships by default


48
49
50
# File 'app/resources/api/v2/work_order_resource.rb', line 48

def project_id
  _model.example_request.initial_project_id
end

#quantityObject


35
36
37
38
39
40
# File 'app/resources/api/v2/work_order_resource.rb', line 35

def quantity
  {
    number: _model.quantity_value,
    unit_of_measurement: _model.quantity_units
  }
end

#source_receptacle_idObject


52
53
54
# File 'app/resources/api/v2/work_order_resource.rb', line 52

def source_receptacle_id
  _model.example_request.asset_id
end

#study_idObject

JSONAPI::Resource doesn't support has_one through relationships by default


43
44
45
# File 'app/resources/api/v2/work_order_resource.rb', line 43

def study_id
  _model.example_request.initial_study_id
end