Class: Search::FindPlates

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

Overview

General purpose flexible search. Can eventually replace a number of existing searches. Allows the user to customise the parameters.

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


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

def scope(user_criteria)
  # We find all plates that do not have transfers where they are the source.  Once a plate has been transferred (or marked
  # for transfer) the destination plate becomes the end of the chain.
  criteria = default_parameters.stringify_keys.merge(user_criteria)

  # External calls will probably use uuids not ids
  criteria['plate_purpose_ids'] = Uuid.where(resource_type: 'Purpose', external_id: criteria['plate_purpose_uuids']).pluck(:resource_id) if criteria['plate_purpose_uuids']
  user = criteria['user_uuid'] ? Uuid.lookup_single_uuid(criteria['user_uuid']).resource : nil
  Plate.with_purpose(criteria['plate_purpose_ids'])
       .for_user(user)
       .include_plates_with_children(criteria['include_used'])
       .page(criteria['page']).per_page(criteria['limit']).order(id: :desc)
end