-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: paginate aidants connect api results
- Loading branch information
1 parent
0b9e844
commit ebc2bc9
Showing
13 changed files
with
138 additions
and
206 deletions.
There are no files selected for viewing
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
41 changes: 12 additions & 29 deletions
41
src/transformer/data/localisation/localisation-from-geo.ts
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 |
---|---|---|
@@ -1,36 +1,19 @@ | ||
import { Adresse, Localisation } from '@gouvfr-anct/lieux-de-mediation-numerique'; | ||
import axios, { AxiosResponse } from 'axios'; | ||
import { Colonne, DataSource, Dissociation, Jonction, LieuxMediationNumeriqueMatching } from '../../input'; | ||
import { NO_LOCALISATION } from '../../fields'; | ||
|
||
export type LocalisationByGeo = { | ||
latitude: string; | ||
longitude: string; | ||
}; | ||
|
||
const isColonne = (colonneToTest: Partial<Colonne> & Partial<Dissociation>): colonneToTest is Colonne => | ||
colonneToTest.colonne != null; | ||
const isValid = (response: AxiosResponse): boolean => | ||
response.data.features[0]?.geometry?.coordinates != null && response.data.features[0].properties.score > 0.7; | ||
|
||
const extractColonneValue = (source: DataSource, field: Colonne | (Jonction & Partial<Colonne>)): string => | ||
isColonne(field) ? source[field.colonne]?.toString() ?? '' : ''; | ||
const toLocalisation = (response: AxiosResponse): Localisation => | ||
Localisation({ | ||
latitude: response.data.features[0].geometry.coordinates[1], | ||
longitude: response.data.features[0].geometry.coordinates[0] | ||
}); | ||
|
||
export const localisationByGeocode = async ( | ||
source: DataSource, | ||
matching: LieuxMediationNumeriqueMatching | ||
): Promise<LocalisationByGeo | undefined> => { | ||
const adresse: string = extractColonneValue(source, matching.adresse) | ||
.replace(/\s*\(.*?\)\s*/gu, ' ') | ||
.replace(/^(?<adresse>.*),.*$/u, '$<adresse>') | ||
.replace(/\s+$/u, '') | ||
.replace(/\s/gu, '+'); | ||
const codePostal: string = extractColonneValue(source, matching.code_postal); | ||
const commune: string = extractColonneValue(source, matching.commune); | ||
export const localisationByGeocode = (adresse: Adresse) => async (): Promise<Localisation> => { | ||
const response: AxiosResponse = await axios.get( | ||
`https://wxs.ign.fr/essentiels/geoportail/geocodage/rest/0.1/search?q=${adresse}&postcode=${codePostal}&city=${commune}` | ||
`https://wxs.ign.fr/essentiels/geoportail/geocodage/rest/0.1/search?q=${adresse.voie}&postcode=${adresse.code_postal}&city=${adresse.commune}` | ||
); | ||
let ignReponse: string[] = []; | ||
if (response.data.features?.[0]?.geometry != null && response.data.features[0].properties.score > 0.7) | ||
ignReponse = response.data.features[0].geometry?.coordinates; | ||
return { | ||
latitude: ignReponse[1]?.toString() ?? '', | ||
longitude: ignReponse[0]?.toString() ?? '' | ||
}; | ||
return isValid(response) ? toLocalisation(response) : NO_LOCALISATION; | ||
}; |
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,3 @@ | ||
import { Adresse, Localisation } from '@gouvfr-anct/lieux-de-mediation-numerique'; | ||
|
||
export type Geocode = (address: Adresse) => () => Promise<Localisation>; |
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,2 @@ | ||
export * from './geocode'; | ||
export * from './localisation.field'; |
Oops, something went wrong.