Class: Dina::Person

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/dina/models/agent/person.rb

Class Method Summary collapse

Methods inherited from BaseModel

custom_headers, find_by_group, #initialize, properties, site

Constructor Details

This class inherits a constructor from Dina::BaseModel

Class Method Details

.endpoint_pathObject



22
23
24
# File 'lib/dina/models/agent/person.rb', line 22

def self.endpoint_path
  "agent-api/"
end

.find_by_email(email:) ⇒ Object

Finds a Person object using an email address

Parameters:

  • email (String)

    an email address



34
35
36
# File 'lib/dina/models/agent/person.rb', line 34

def self.find_by_email(email:)
  where("email": email).all
end

.search_by_name(name:) ⇒ Object

Searches for a Person by name using the search module

Parameters:

  • name (String)

    any portion of a person’s name



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/dina/models/agent/person.rb', line 42

def self.search_by_name(name:)
  payload = {
    query: {
      multi_match: {
        query: name,
        type: :cross_fields,
        fields: [
          "data.attributes.familyNames^3",
          "data.attributes.givenNames",
          "data.attributes.displayName^5",
          "data.attributes.aliases",
          "data.attributes.displayName.autocomplete"
        ]
      }
    }
  }
  hits = Search.execute(index: "agent", payload: payload)[:hits]
  hits.map{|a| self.find(a[:_source][:data][:id]).first }
end

.table_nameObject



26
27
28
# File 'lib/dina/models/agent/person.rb', line 26

def self.table_name
  "person"
end