Skip to content

Commit

Permalink
add filters
Browse files Browse the repository at this point in the history
  • Loading branch information
tycol7 committed Nov 7, 2024
1 parent 9ca7e3e commit 2f7b111
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ def index
service = ManageRepresentativeService.new(external_uid: 'power_of_attorney_request_uid',
external_key: 'power_of_attorney_request_key')

res = service.read_poa_request(poa_codes:, page_size:, page_index:)
res = service.read_poa_request(poa_codes:, page_size:, page_index:, filter:)

poa_list = res['poaRequestRespondReturnVOList']

Expand Down Expand Up @@ -136,7 +136,7 @@ def build_bgs_attributes(form_attributes)
def validate_filter!(filter)
return nil if filter.blank?

valid_filters = %w[status state city country sensitivityLevel]
valid_filters = %w[status state city country]

invalid_filters = filter.keys - valid_filters

Expand All @@ -158,9 +158,9 @@ def validate_statuses!(statuses)
)
end

valid_statuses = %w[new accepted declined]
valid_statuses = ManageRepresentativeService::ALL_STATUSES

if statuses.any? { |status| valid_statuses.exclude?(status.downcase) }
if statuses.any? { |status| valid_statuses.exclude?(status.upcase) }
raise ::Common::Exceptions::UnprocessableEntity.new(
detail: "Status(es) must be one of: #{valid_statuses.join(', ')}"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,48 @@

module ClaimsApi
class ManageRepresentativeService < ClaimsApi::LocalBGS
ALL_STATUSES = %w[NEW ACCEPTED DECLINED].freeze

def bean_name
'VDC/ManageRepresentativeService'
end

def read_poa_request(poa_codes: [], page_size: nil, page_index: nil) # rubocop:disable Metrics/MethodLength
def read_poa_request(poa_codes: [], page_size: nil, page_index: nil, filter: {}) # rubocop:disable Metrics/MethodLength
# Workaround to allow multiple roots in the Nokogiri XML builder
# https://stackoverflow.com/a/4907450
doc = Nokogiri::XML::DocumentFragment.parse ''

status_list = filter['status'].presence || ALL_STATUSES
state = filter['state']
city = filter['city']
country = filter['country']

Nokogiri::XML::Builder.with(doc) do |xml|
xml.send('data:POACodeList') do
poa_codes.each do |poa_code|
xml.POACode poa_code
end
end
xml.send('data:SecondaryStatusList') do
%w[New Pending Accepted Declined].each do |status|
status_list.each do |status|
xml.SecondaryStatus status
end
end
if state
xml.send('data:StateList') do
xml.State state
end
end
if city
xml.send('data:CityList') do
xml.City city
end
end
if country
xml.send('data:CountryList') do
xml.Country country
end
end
if page_size || page_index
xml.send('data:POARequestParameter') do
xml.pageSize page_size if page_size
Expand Down

0 comments on commit 2f7b111

Please sign in to comment.