Skip to content

Commit

Permalink
[ART] POA request representative
Browse files Browse the repository at this point in the history
  • Loading branch information
nihil2501 committed Dec 31, 2024
1 parent 4adfce0 commit 7cf18dc
Show file tree
Hide file tree
Showing 9 changed files with 140 additions and 5 deletions.
5 changes: 5 additions & 0 deletions app/models/accredited_individual.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ class AccreditedIndividual < ApplicationRecord
has_many :accreditations, dependent: :destroy
has_many :accredited_organizations, through: :accreditations

has_many :power_of_attorney_requests,
as: :power_of_attorney_holder,
inverse_of: :power_of_attorney_holder,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest'

validates :ogc_id, :registration_number, :individual_type, presence: true
validates :poa_code, length: { is: 3 }, allow_blank: true
validates :individual_type, uniqueness: { scope: :registration_number }
Expand Down
5 changes: 5 additions & 0 deletions app/models/accredited_organization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ class AccreditedOrganization < ApplicationRecord
has_many :accreditations, dependent: :destroy
has_many :accredited_individuals, through: :accreditations

has_many :power_of_attorney_requests,
as: :power_of_attorney_holder,
inverse_of: :power_of_attorney_holder,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequest'

validates :ogc_id, :poa_code, presence: true
validates :poa_code, length: { is: 3 }
validates :poa_code, uniqueness: true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,31 @@ module AccreditedRepresentativePortal
module V0
class PowerOfAttorneyRequestsController < ApplicationController
def index
poa_requests = PowerOfAttorneyRequest.includes(resolution: :resolving).limit(100)
poa_requests = poa_requests_rel.limit(100)
serializer = PowerOfAttorneyRequestSerializer.new(poa_requests)

render json: serializer.serializable_hash, status: :ok
end

def show
poa_request = PowerOfAttorneyRequest.includes(resolution: :resolving).find(params[:id])
poa_request = poa_requests_rel.find(params[:id])
serializer = PowerOfAttorneyRequestSerializer.new(poa_request)

render json: serializer.serializable_hash, status: :ok
rescue ActiveRecord::RecordNotFound
render json: { error: 'Record not found' }, status: :not_found
end

private

def poa_requests_rel
PowerOfAttorneyRequest.includes(
:power_of_attorney_form,
:power_of_attorney_holder,
:accredited_individual,
resolution: :resolving
)
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ module ClaimantTypes
belongs_to :claimant, class_name: 'UserAccount'

has_one :power_of_attorney_form,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyForm',
inverse_of: :power_of_attorney_request,
required: true

has_one :resolution,
class_name: 'AccreditedRepresentativePortal::PowerOfAttorneyRequestResolution',
inverse_of: :power_of_attorney_request

belongs_to :power_of_attorney_holder,
inverse_of: :power_of_attorney_requests,
polymorphic: true

belongs_to :accredited_individual

before_validation :set_claimant_type

private
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,17 @@ class PowerOfAttorneyRequestSerializer < ApplicationSerializer
.new(poa_request.resolution)
.serializable_hash
end

attribute :power_of_attorney_holder do |poa_request|
PowerOfAttorneyHolderSerializer
.new(poa_request.power_of_attorney_holder)
.serializable_hash
end

attribute :accredited_individual do |poa_request|
AccreditedIndividualSerializer
.new(poa_request.accredited_individual)
.serializable_hash
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestSerializer
class AccreditedIndividualSerializer < ApplicationSerializer
attribute :full_name do |poa_holder|
parts = [
poa_holder.first_name,
poa_holder.middle_initial,
poa_holder.last_name
]

parts.reject(&:blank?).join(' ')
end
end
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

module AccreditedRepresentativePortal
class PowerOfAttorneyRequestSerializer
class PowerOfAttorneyHolderSerializer < ApplicationSerializer
attribute :type do |poa_holder|
case poa_holder
when AccreditedIndividual
"accredited_#{poa_holder.individual_type}"
when AccreditedOrganization
'veteran_service_organization'
end
end

with_options if: proc { |poa_holder| poa_holder.is_a?(AccreditedOrganization) } do
attribute :name
end

with_options if: proc { |poa_holder| poa_holder.is_a?(AccreditedIndividual) } do
attribute :full_name do |poa_holder|
parts = [
poa_holder.first_name,
poa_holder.middle_initial,
poa_holder.last_name
]

parts.reject(&:blank?).join(' ')
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
association :claimant, factory: :user_account
association :power_of_attorney_form, strategy: :build

association :power_of_attorney_holder, factory: [:accredited_organization, :with_representatives]
accredited_individual { power_of_attorney_holder.accredited_individuals.first }

trait :with_acceptance do
resolution { create(:power_of_attorney_request_resolution, :acceptance) }
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
end

describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests' do
it 'returns the list of power of attorney requests', skip: 'temporarily for a migration' do
it 'returns the list of power of attorney requests' do
poa_requests

get('/accredited_representative_portal/v0/power_of_attorney_requests')
Expand Down Expand Up @@ -88,6 +88,15 @@
'email' => '[email protected]'
}
},
'power_of_attorney_holder' => {
'id' => poa_requests[0].power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_requests[0].power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_requests[0].accredited_individual.id,
'full_name' => "#{poa_requests[0].accredited_individual.first_name} #{poa_requests[0].accredited_individual.last_name}",
},
'resolution' => nil
},
{
Expand Down Expand Up @@ -145,6 +154,15 @@
'email' => '[email protected]'
}
},
'power_of_attorney_holder' => {
'id' => poa_requests[1].power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_requests[1].power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_requests[1].accredited_individual.id,
'full_name' => "#{poa_requests[1].accredited_individual.first_name} #{poa_requests[1].accredited_individual.last_name}",
},
'resolution' => {
'id' => poa_requests[1].resolution.id,
'type' => 'decision',
Expand Down Expand Up @@ -208,6 +226,15 @@
'email' => '[email protected]'
}
},
'power_of_attorney_holder' => {
'id' => poa_requests[2].power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_requests[2].power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_requests[2].accredited_individual.id,
'full_name' => "#{poa_requests[2].accredited_individual.first_name} #{poa_requests[2].accredited_individual.last_name}",
},
'resolution' => {
'id' => poa_requests[2].resolution.id,
'type' => 'decision',
Expand Down Expand Up @@ -272,6 +299,15 @@
'email' => '[email protected]'
}
},
'power_of_attorney_holder' => {
'id' => poa_requests[3].power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_requests[3].power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_requests[3].accredited_individual.id,
'full_name' => "#{poa_requests[3].accredited_individual.first_name} #{poa_requests[3].accredited_individual.last_name}",
},
'resolution' => {
'id' => poa_requests[3].resolution.id,
'type' => 'expiration',
Expand All @@ -284,7 +320,7 @@
end

describe 'GET /accredited_representative_portal/v0/power_of_attorney_requests/:id' do
it 'returns the details of a specific power of attorney request', skip: 'temporarily for a migration' do
it 'returns the details of a specific power of attorney request' do
get("/accredited_representative_portal/v0/power_of_attorney_requests/#{poa_request.id}")

parsed_response = JSON.parse(response.body)
Expand Down Expand Up @@ -353,6 +389,15 @@
'creator_id' => poa_request.resolution.resolving.creator_id,
'reason' => 'Didn\'t authorize treatment record disclosure',
'decision_type' => 'declination'
},
'power_of_attorney_holder' => {
'id' => poa_request.power_of_attorney_holder.id,
'type' => 'veteran_service_organization',
'name' => poa_request.power_of_attorney_holder.name
},
'accredited_individual' => {
'id' => poa_request.accredited_individual.id,
'full_name' => "#{poa_request.accredited_individual.first_name} #{poa_request.accredited_individual.last_name}",
}
}
)
Expand Down

0 comments on commit 7cf18dc

Please sign in to comment.