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, #fetchable_fields, inclusions, resolve_relationship_names_to_relations, updatable_fields

Instance Method Details

#optionsObject


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

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

#order_typeObject


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

def order_type
  _model.work_order_type.name
end

#project_idObject

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


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

def project_id
  _model.example_request.initial_project_id
end

#quantityObject


39
40
41
# File 'app/resources/api/v2/work_order_resource.rb', line 39

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

#source_receptacle_idObject


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

def source_receptacle_id
  _model.example_request.asset_id
end

#study_idObject

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


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

def study_id
  _model.example_request.initial_study_id
end