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) {
|
function buildURL(scope: string, term: string, extra?: string) {
|
||||||
term = encodeURIComponent(term.replace(/\(|\)/g, ''));
|
term = encodeURIComponent(term.replace(/\(|\)/g, ''));
|
||||||
if (scope === 'adresse') {
|
const params = new URLSearchParams();
|
||||||
return `${api_adresse_url}/search?q=${term}&limit=${API_ADRESSE_QUERY_LIMIT}`;
|
let path = `${api_geo_url}/${scope}`;
|
||||||
} else if (scope === 'annuaire-education') {
|
|
||||||
return `${api_education_url}/search?dataset=fr-en-annuaire-education&q=${term}&rows=${API_EDUCATION_QUERY_LIMIT}`;
|
if (scope == 'adresse') {
|
||||||
} else if (scope === 'communes') {
|
path = `${api_adresse_url}/search`;
|
||||||
const limit = `limit=${API_GEO_COMMUNES_QUERY_LIMIT}`;
|
params.set('q', term);
|
||||||
const url = extra
|
params.set('limit', `${API_ADRESSE_QUERY_LIMIT}`);
|
||||||
? `${api_geo_url}/communes?codeDepartement=${extra}&${limit}&`
|
} else if (scope == 'annuaire-education') {
|
||||||
: `${api_geo_url}/communes?${limit}&`;
|
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)) {
|
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`;
|
params.set('limit', `${API_GEO_COMMUNES_QUERY_LIMIT}`);
|
||||||
} else if (isNumeric(term)) {
|
} else {
|
||||||
const code = term.padStart(2, '0');
|
if (isNumeric(term)) {
|
||||||
return `${api_geo_url}/${scope}?code=${code}&limit=${API_GEO_QUERY_LIMIT}`;
|
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 ({
|
const defaultQueryFn: QueryFunction<unknown, QueryKey> = async ({
|
||||||
|
|
|
@ -35,7 +35,7 @@ class APIGeoService
|
||||||
end
|
end
|
||||||
|
|
||||||
def departements
|
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
|
end
|
||||||
|
|
||||||
def departement_name(code)
|
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
|
describe 'departements', vcr: { cassette_name: 'api_geo_departements' } do
|
||||||
it 'return sorted results' 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.first).to eq(code: '99', name: 'Etranger')
|
||||||
expect(APIGeoService.departements.second).to eq(code: '01', name: 'Ain')
|
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
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue