Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BE | Ask va api Fix Inquiry bug and create FacilitiesDataJob #19976

Merged
merged 4 commits into from
Dec 20, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions lib/periodic_jobs.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@
# Update Optionset data cache
mgr.register('0 0 * * *', 'Crm::OptionsetDataJob')

# Update Facilities data cache
mgr.register('0 0 * * *', 'Crm::FacilitiesDataJob')

# Update FormSubmissionAttempt status from Lighthouse Benefits Intake API
mgr.register('0 0 * * *', 'BenefitsIntakeStatusJob')

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,20 @@ def search
api_result.tmp_covid_online_scheduling = mobile_api_get_by_id(api_result.id)
end
end
render_json(serializer, lighthouse_params, api_results)

patsr_approved_codes = retrieve_patsr_approved_facilities.pluck(:FacilityCode)

filtered_results = WillPaginate::Collection.create(
api_results.current_page,
api_results.per_page,
api_results.total_entries
) do |pager|
filtered_items = api_results.select { |object| patsr_approved_codes.include?(object.unique_id) }
pager.replace(filtered_items)
pager.total_entries = filtered_items.size
end

render_json(serializer, lighthouse_params, filtered_results)
end

def show
Expand All @@ -28,6 +41,11 @@ def show

private

def retrieve_patsr_approved_facilities
data = Crm::CacheData.new.fetch_and_cache_data(endpoint: 'Facilities', cache_key: 'Facilities', payload: {})
JSON.parse(data, symbolize_names: true)[:Data]
end

def api
FacilitiesApi::V2::Lighthouse::Client.new
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ def call
inquiry_details = base_inquiry_details(inquiry_params[:your_role])

if education_benefits?(inquiry_params[:select_category],
inquiry_params[:select_topic])
inquiry_params[:select_topic]) ||
inquiry_params[:who_is_your_question_about] == "It's a general question"
return general_inquiry(inquiry_params, inquiry_details)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def fetch_state(state_code)
def formatted_pronouns(pronouns)
return unless pronouns

pronouns[:pronouns_not_listed_text].presence || pronouns.key(true)&.to_s&.tr('_', '/')
pronouns[:pronouns_not_listed_text].presence || pronouns.key('true')&.to_s&.tr('_', '/')
end

def contact_field(field, inquiry_details, inquiry_params)
Expand Down
28 changes: 28 additions & 0 deletions modules/ask_va_api/app/sidekiq/crm/facilities_data_job.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# frozen_string_literal: true

require 'sidekiq'

module Crm
class FacilitiesDataJob
include Sidekiq::Job

# Schedule to run every 24 hours. Adjust as needed.
sidekiq_options retry: false, unique_for: 24.hours

def perform
Crm::CacheData.new.fetch_and_cache_data(endpoint: 'Facilities', cache_key: 'Facilities', payload: {})
rescue => e
log_error('optionset', e)
end

private

def log_error(action, exception)
LogService.new.call(action) do |span|
span.set_tag('error', true)
span.set_tag('error.msg', exception.message)
end
Rails.logger.error("Error during #{action}: #{exception.message}")
end
end
end
177 changes: 177 additions & 0 deletions modules/ask_va_api/config/locales/get_facilities_mock_data.json

Large diffs are not rendered by default.

Loading
Loading