Skip to content

Commit

Permalink
More relationships for search/suggestion
Browse files Browse the repository at this point in the history
  • Loading branch information
bemky committed Sep 21, 2017
1 parent db594a9 commit e1d88c0
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 2 deletions.
10 changes: 10 additions & 0 deletions lib/mls/account.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ class Account < MLS::Model
has_many :services, as: :subject
has_many :tim_alerts

has_many :searches
has_many :deals, class_name: "Search", foreign_key: "broker_id"
has_many :suggestions, foreign_key: "suggested_by_id"

has_many :credit_cards

has_many :email_addresses do
Expand Down Expand Up @@ -157,6 +161,12 @@ def send_confirmation_email(url)
req.body = {url: url}.to_json
Account.connection.instance_variable_get(:@connection).send_request(req)
end

def set_confirmation_token
req = Net::HTTP::Get.new("/accounts/#{self.id}/confirm")
response = Account.connection.instance_variable_get(:@connection).send_request(req)
self.confirmation_token = response.body
end


end
5 changes: 4 additions & 1 deletion lib/mls/email_digest.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
class EmailDigest < MLS::Model

belongs_to :search
belongs_to :account
accepts_nested_attributes_for :account

def filter
JSON.parse (read_attribute(:filter) || {}).to_json, object_class: OpenStruct
filter_to_read = read_attribute(:filter)
filter_to_read = search.filter if filter_to_read&.empty? && search
JSON.parse (filter_to_read || {}).to_json, object_class: OpenStruct
end

end
8 changes: 8 additions & 0 deletions lib/mls/search.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
class Search < MLS::Model

STATUS_OPTIONS = %w(active closed nurturing)
STAGE_OPTIONS = %w(initiated delivered connected toured loi signed)

belongs_to :account
belongs_to :broker, class_name: "Account"
belongs_to :manager, class_name: "Account"

has_many :suggestions
has_many :email_digests

def filter
JSON.parse (read_attribute(:filter) || {}).to_json, object_class: OpenStruct
end

def regions
Region.where(id: self.region_ids)
end

end
4 changes: 3 additions & 1 deletion lib/mls/suggestion.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
class Suggestion < MLS::Model


STATUS_OPTIONS = %w(proposed confirmed rejected)

belongs_to :search
belongs_to :listing
belongs_to :suggested_by, class_name: "Account"
Expand Down

0 comments on commit e1d88c0

Please sign in to comment.