Class: Search::FindTubes

Inherits:
Search show all
Defined in:
app/models/search/find_tubes.rb

Instance Method Summary collapse

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

Methods inherited from ApplicationRecord

convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Warren::BroadcastMessages

#broadcast, included, #queue_associated_for_broadcast, #queue_for_broadcast, #warren

Instance Method Details

#scope(user_criteria) ⇒ Object


4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/models/search/find_tubes.rb', line 4

def scope(user_criteria)
  criteria = default_parameters.stringify_keys.merge(user_criteria)

  purpose_ids = if criteria['tube_purpose_uuids']
                  Uuid.where(resource_type: 'Purpose', external_id: criteria['tube_purpose_uuids'])
                      .pluck(:resource_id)
                else
                  criteria['tube_purpose_ids']
                end

  Tube.with_purpose(purpose_ids)
      .include_plates_with_children(criteria['include_used'])
      .includes(:transfer_requests_as_target, aliquots: Io::Aliquot::PRELOADS)
      .page(criteria['page']).limit(criteria['limit']).order(id: :desc)
end