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, #english_description, find_by_group, #french_description, #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



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/dina/models/agent/person.rb', line 38

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 = Dina::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