feat(apigeo): enable all zones on departements api
This commit is contained in:
parent
d943e34b6d
commit
bdb15aaa4a
5 changed files with 51 additions and 33 deletions
|
@ -27,24 +27,42 @@ type QueryKey = readonly [
|
|||
|
||||
function buildURL(scope: string, term: string, extra?: string) {
|
||||
term = encodeURIComponent(term.replace(/\(|\)/g, ''));
|
||||
if (scope === 'adresse') {
|
||||
return `${api_adresse_url}/search?q=${term}&limit=${API_ADRESSE_QUERY_LIMIT}`;
|
||||
} else if (scope === 'annuaire-education') {
|
||||
return `${api_education_url}/search?dataset=fr-en-annuaire-education&q=${term}&rows=${API_EDUCATION_QUERY_LIMIT}`;
|
||||
} else if (scope === 'communes') {
|
||||
const limit = `limit=${API_GEO_COMMUNES_QUERY_LIMIT}`;
|
||||
const url = extra
|
||||
? `${api_geo_url}/communes?codeDepartement=${extra}&${limit}&`
|
||||
: `${api_geo_url}/communes?${limit}&`;
|
||||
const params = new URLSearchParams();
|
||||
let path = `${api_geo_url}/${scope}`;
|
||||
|
||||
if (scope == 'adresse') {
|
||||
path = `${api_adresse_url}/search`;
|
||||
params.set('q', term);
|
||||
params.set('limit', `${API_ADRESSE_QUERY_LIMIT}`);
|
||||
} else if (scope == 'annuaire-education') {
|
||||
path = `${api_education_url}/search`;
|
||||
params.set('q', term);
|
||||
params.set('rows', `${API_EDUCATION_QUERY_LIMIT}`);
|
||||
params.set('dataset', 'fr-en-annuaire-education');
|
||||
} else if (scope == 'communes') {
|
||||
if (extra) {
|
||||
params.set('codeDepartement', extra);
|
||||
}
|
||||
if (isNumeric(term)) {
|
||||
return `${url}codePostal=${term}`;
|
||||
params.set('codePostal', term);
|
||||
} else {
|
||||
params.set('nom', term);
|
||||
params.set('boost', 'population');
|
||||
}
|
||||
return `${url}nom=${term}&boost=population`;
|
||||
} else if (isNumeric(term)) {
|
||||
const code = term.padStart(2, '0');
|
||||
return `${api_geo_url}/${scope}?code=${code}&limit=${API_GEO_QUERY_LIMIT}`;
|
||||
params.set('limit', `${API_GEO_COMMUNES_QUERY_LIMIT}`);
|
||||
} else {
|
||||
if (isNumeric(term)) {
|
||||
params.set('code', term.padStart(2, '0'));
|
||||
} else {
|
||||
params.set('nom', term);
|
||||
}
|
||||
return `${api_geo_url}/${scope}?nom=${term}&limit=${API_GEO_QUERY_LIMIT}`;
|
||||
if (scope == 'departements') {
|
||||
params.set('zone', 'metro,drom,com');
|
||||
}
|
||||
params.set('limit', `${API_GEO_QUERY_LIMIT}`);
|
||||
}
|
||||
|
||||
return `${path}?${params}`;
|
||||
}
|
||||
|
||||
const defaultQueryFn: QueryFunction<unknown, QueryKey> = async ({
|
||||
|
|
|
@ -35,7 +35,7 @@ class APIGeoService
|
|||
end
|
||||
|
||||
def departements
|
||||
[{ code: '99', name: 'Etranger' }] + get_from_api_geo(:departements).sort_by { _1[:code] }
|
||||
[{ code: '99', name: 'Etranger' }] + get_from_api_geo('departements?zone=metro,drom,com').sort_by { _1[:code] }
|
||||
end
|
||||
|
||||
def departement_name(code)
|
||||
|
|
16
spec/fixtures/cassettes/api_geo_all.yml
vendored
16
spec/fixtures/cassettes/api_geo_all.yml
vendored
File diff suppressed because one or more lines are too long
12
spec/fixtures/cassettes/api_geo_departements.yml
vendored
12
spec/fixtures/cassettes/api_geo_departements.yml
vendored
File diff suppressed because one or more lines are too long
|
@ -36,10 +36,10 @@ describe APIGeoService do
|
|||
|
||||
describe 'departements', vcr: { cassette_name: 'api_geo_departements' } do
|
||||
it 'return sorted results' do
|
||||
expect(APIGeoService.departements.size).to eq(102)
|
||||
expect(APIGeoService.departements.size).to eq(110)
|
||||
expect(APIGeoService.departements.first).to eq(code: '99', name: 'Etranger')
|
||||
expect(APIGeoService.departements.second).to eq(code: '01', name: 'Ain')
|
||||
expect(APIGeoService.departements.last).to eq(code: '976', name: 'Mayotte')
|
||||
expect(APIGeoService.departements.last).to eq(code: '989', name: 'Île de Clipperton')
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in a new issue