Skip to content

Instantly share code, notes, and snippets.

@perchwellkhan
perchwellkhan / listings.rb
Created October 7, 2025 13:31
Update aor_id in the listing transfer service
# frozen_string_literal: true
module Transfer
class Listings < ServiceObject
TRANSFER_LIMIT = 500
def initialize(to_brokerage, to_office, to_agents, listings, open_house_listing_agent: nil, user: nil)
super()
raise "Too many listings: #{listings.count}, limit is #{TRANSFER_LIMIT}" if listings.count > TRANSFER_LIMIT
@to_brokerage = to_brokerage
@perchwellkhan
perchwellkhan / open_house.rb
Last active October 7, 2025 16:16
update an openHouse listing_agent
#@param agent_id
#@param user
#
#This method will simply update the listing_agent_id column for an openhouse, reindex and call the synchronizer
#The synchronizer has policies according to MLS to sync to external listing service
def transfer_listing_agent(agent_id, user: nil)
unless self.listing.agents.pluck(:id).include?(agent_id)
Rails.logger.info("Agent Id: #{agent_id} is invalid"
return
end
@perchwellkhan
perchwellkhan / agents.rb
Created October 7, 2025 12:59
Agent Transfer Service
#services/transfer/agent.rb
def initialize(agent:, office:, selected_listings: [], user:)
@agent = agent
@from_office = agent.office
@to_office = office
@to_brokerage = office.brokerage
@to_aor = office.aor
@user = user
@selected_listing_ids = selected_listing_ids.map(&:to_i)
# @param Agent_ID [Integer] ID of the agent being transferred
# @param Office_ID [Integer] ID of the new office the agent belongs to
# @param Listing_IDs [Array&lt;Integer&gt;] Ids of listings transferring
#
# @return render JSON
# /api/manage_people/v1/agents_controller(an RPC member route)
module API
module Transfer
module V1