-
Notifications
You must be signed in to change notification settings - Fork 66
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into dbex/80718-TE-transform-2
- Loading branch information
Showing
47 changed files
with
1,196 additions
and
215 deletions.
There are no files selected for viewing
Validating CODEOWNERS rules …
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'accredited_representation/constants' | ||
|
||
class AccreditedIndividual < ApplicationRecord | ||
# rubocop:disable Rails/HasAndBelongsToMany | ||
has_and_belongs_to_many :accredited_organizations, | ||
class: 'AccreditedOrganization', | ||
join_table: 'accredited_individuals_accredited_organizations' | ||
|
||
# rubocop:enable Rails/HasAndBelongsToMany | ||
|
||
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 } | ||
|
||
enum individual_type: { | ||
'attorney' => 'attorney', | ||
'claims_agent' => 'claims_agent', | ||
'representative' => 'representative' | ||
} | ||
|
||
# Find all [AccreditedIndividuals] that are located within a distance of a specific location | ||
# @param long [Float] longitude of the location of interest | ||
# @param lat [Float] latitude of the location of interest | ||
# @param max_distance [Float] the maximum search distance in meters | ||
# | ||
# @return [AccreditedIndividual::ActiveRecord_Relation] an ActiveRecord_Relation of | ||
# all individuals matching the search criteria | ||
def self.find_within_max_distance(long, lat, max_distance = AccreditedRepresentation::Constants::DEFAULT_MAX_DISTANCE) | ||
query = 'ST_DWithin(ST_SetSRID(ST_MakePoint(:long, :lat), 4326)::geography, location, :max_distance)' | ||
params = { long:, lat:, max_distance: } | ||
|
||
where(query, params) | ||
end | ||
|
||
# return all poa_codes associated with the individual | ||
# | ||
# @return [Array<String>] | ||
def poa_codes | ||
([poa_code] + accredited_organizations.pluck(:poa_code)).compact | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# frozen_string_literal: true | ||
|
||
require 'accredited_representation/constants' | ||
|
||
class AccreditedOrganization < ApplicationRecord | ||
# rubocop:disable Rails/HasAndBelongsToMany | ||
has_and_belongs_to_many :accredited_individuals, | ||
class: 'AccreditedIndividual', | ||
join_table: 'accredited_individuals_accredited_organizations' | ||
# rubocop:enable Rails/HasAndBelongsToMany | ||
|
||
validates :ogc_id, :poa_code, presence: true | ||
validates :poa_code, length: { is: 3 } | ||
validates :poa_code, uniqueness: true | ||
|
||
# | ||
# Find all [AccreditedOrganizations] that are located within a distance of a specific location | ||
# @param long [Float] longitude of the location of interest | ||
# @param lat [Float] latitude of the location of interest | ||
# @param max_distance [Float] the maximum search distance in meters | ||
# | ||
# @return [AccreditedOrganization::ActiveRecord_Relation] an ActiveRecord_Relation of | ||
# all organizations matching the search criteria | ||
def self.find_within_max_distance(long, lat, max_distance = AccreditedRepresentation::Constants::DEFAULT_MAX_DISTANCE) | ||
query = 'ST_DWithin(ST_SetSRID(ST_MakePoint(:long, :lat), 4326)::geography, location, :max_distance)' | ||
params = { long:, lat:, max_distance: } | ||
|
||
where(query, params) | ||
end | ||
|
||
# return all registration_numbers associated with the individual | ||
# | ||
# @return [Array<String>] | ||
def registration_numbers | ||
accredited_individuals.pluck(:registration_number) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# frozen_string_literal: true | ||
|
||
module AccreditedRepresentation | ||
module Constants | ||
METERS_PER_MILE = 1609.344 | ||
DEFAULT_MAX_MILES = 50 | ||
DEFAULT_MAX_DISTANCE = DEFAULT_MAX_MILES * METERS_PER_MILE | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.