Skip to content

Commit

Permalink
Fetch supported jobs from within model
Browse files Browse the repository at this point in the history
  • Loading branch information
allthesignals committed Feb 27, 2025
1 parent f8de0ab commit 4f12182
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
7 changes: 1 addition & 6 deletions app/app/controllers/webhooks/pinwheel/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,8 @@ def create
end

if params["event"] == "account.added"
supported_jobs = get_supported_jobs(params["payload"]["platform_id"])
PayrollAccount
.create_with(cbv_flow: @cbv_flow, supported_jobs: supported_jobs)
.create_with(cbv_flow: @cbv_flow)
.find_or_create_by(pinwheel_account_id: params["payload"]["account_id"])
track_account_created_event(@cbv_flow, params["payload"]["platform_name"])
end
Expand Down Expand Up @@ -92,8 +91,4 @@ def set_cbv_flow
def set_pinwheel
@pinwheel = @cbv_flow.present? ? pinwheel_for(@cbv_flow) : PinwheelService.new("sandbox", DUMMY_API_KEY)
end

def get_supported_jobs(platform_id)
@pinwheel.fetch_platform(platform_id: platform_id)["data"]["supported_jobs"]
end
end
17 changes: 17 additions & 0 deletions app/app/models/payroll_account/pinwheel.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
class PayrollAccount::Pinwheel < PayrollAccount
after_create :lookup_supported_jobs

EVENTS_MAP = {
"employment.added" => :employment_synced_at,
"income.added" => :income_synced_at,
Expand Down Expand Up @@ -54,4 +56,19 @@ def event_columns_for(job)

[ error_column, sync_column ]
end

def lookup_supported_jobs
platform_id = pinwheel.fetch_account(account_id: pinwheel_account_id)["data"]["platform_id"]
supported_jobs = pinwheel.fetch_platform(platform_id: platform_id)["data"]["supported_jobs"]

update(supported_jobs: supported_jobs)
end

def pinwheel
PinwheelService.new(site_config[cbv_flow.client_agency_id].pinwheel_environment)
end

def site_config
Rails.application.config.client_agencies
end
end
4 changes: 4 additions & 0 deletions app/app/services/pinwheel_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ def fetch_items(options)
@http.get(build_url(ITEMS_ENDPOINT), options).body
end

def fetch_account(account_id:)
json = @http.get(build_url("#{ACCOUNTS_ENDPOINT}/#{account_id}")).body
end

def fetch_accounts(end_user_id:)
@http.get(build_url("#{END_USERS}/#{end_user_id}/accounts")).body
end
Expand Down

0 comments on commit 4f12182

Please sign in to comment.