fix(search): share provincial hierarchy across legacy and catalogue APIs
This commit is contained in:
@@ -12,6 +12,21 @@ final class InvestmentGeography
|
||||
{
|
||||
public const FIELDS = ['province_id' => 'province', 'district_id' => 'district', 'admin_post_id' => 'admin_post', 'locality_id' => 'locality'];
|
||||
|
||||
/** Resolve an old province-name search only when the public register has exactly one match. */
|
||||
public function provinceSearch(array $filters): array
|
||||
{
|
||||
if (empty($filters['province_id']) && is_string($filters['province'] ?? null) && trim($filters['province']) !== '') {
|
||||
$matches = $this->publicReferences()->where('location_type', 'province')
|
||||
->whereRaw('lower(btrim(name)) = ?', [mb_strtolower(trim($filters['province']))])->limit(2)->get(['id']);
|
||||
if ($matches->count() === 1) {
|
||||
$filters['province_id'] = $matches[0]->id;
|
||||
unset($filters['province']);
|
||||
}
|
||||
}
|
||||
|
||||
return $filters;
|
||||
}
|
||||
|
||||
/**
|
||||
* Restrict published dossier searches using direct territories and public, validated structure links.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user