Class: Search::FindPlatesForUser

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

Instance Method Summary collapse

Methods included from Uuid::Uuidable

included, #unsaved_uuid!, #uuid

Methods inherited from ApplicationRecord

alias_association, convert_labware_to_receptacle_for, find_by_id_or_name, find_by_id_or_name!

Methods included from Squishify

extended

Instance Method Details

#scope(user_criteria) ⇒ Object

rubocop:todo Metrics/AbcSize, Metrics/MethodLength



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/models/search/find_plates_for_user.rb', line 3

def scope(user_criteria) # rubocop:todo Metrics/AbcSize, Metrics/MethodLength
  # 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
  if criteria['plate_purpose_uuids']
    criteria['plate_purpose_ids'] = Uuid.where(
      resource_type: 'Purpose',
      external_id: criteria['plate_purpose_uuids']
    ).pluck(:id)
  end

  Plate
    .with_purpose(criteria['plate_purpose_ids'])
    .for_user(Uuid.lookup_single_uuid(criteria['user_uuid']).resource)
    .include_labware_with_children(criteria['include_used'])
    .page(criteria['page'])
    .limit(criteria['limit'])
    .order('plate_owners.id DESC')
end