generated from bcgov/quickstart-openshift
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
COMPENF-648-Changed location parameters from param types to query typ…
…es (#115)
- Loading branch information
Showing
6 changed files
with
74 additions
and
44 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
60 changes: 37 additions & 23 deletions
60
backend/src/external_api/bc_geo_coder/bc_geo_coder.service.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,30 +1,44 @@ | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { HttpService } from '@nestjs/axios'; | ||
import { catchError, firstValueFrom } from 'rxjs'; | ||
import { AxiosError} from 'axios'; | ||
import { Feature } from 'src/types/bc_geocoder/bcGeocoderType'; | ||
import { Injectable, Logger } from "@nestjs/common"; | ||
import { HttpService } from "@nestjs/axios"; | ||
import { catchError, firstValueFrom } from "rxjs"; | ||
import { AxiosError } from "axios"; | ||
import { Feature } from "src/types/bc_geocoder/bcGeocoderType"; | ||
|
||
@Injectable() | ||
export class BcGeoCoderService { | ||
private readonly logger = new Logger(BcGeoCoderService.name); | ||
|
||
private readonly logger = new Logger(BcGeoCoderService.name); | ||
|
||
constructor(private readonly httpService: HttpService) {} | ||
|
||
async findAll(query: string): Promise<Feature> { | ||
const maxResults = 10; | ||
const apiUrl = `${process.env.BC_GEOCODER_API_URL}/addresses.json?addressString=${query}&locationDescriptor=any&maxResults=${maxResults}&interpolation=adaptive&echo=true&brief=false&autoComplete=true&setBack=0&outputSRS=4326&minScore=2&provinceCode=BC`; | ||
|
||
const { data } = await firstValueFrom( | ||
this.httpService.get<any>(apiUrl).pipe( | ||
catchError((error: AxiosError) => { | ||
this.logger.error(error.response.data); | ||
throw 'Error getting BC Geocoder response'; | ||
}), | ||
), | ||
); | ||
return data; | ||
constructor(private readonly httpService: HttpService) {} | ||
|
||
// given a localityName (community, for example) and an address, return the Feature given by BC Geocoder | ||
async findAll(localityName: string, addressString: string): Promise<Feature> { | ||
const maxResults = 10; | ||
let apiUrl: string; | ||
this.logger.debug( | ||
`Calling BC Geocoder. Parameters sent to backend were localityName: ${localityName} and addressString: ${addressString}` | ||
); | ||
if (addressString && localityName) { | ||
this.logger.debug( | ||
`Calling BC Geocoder with address ${addressString} and community ${localityName}` | ||
); | ||
apiUrl = `${process.env.BC_GEOCODER_API_URL}/addresses.json?addressString=${addressString}&locationDescriptor=any&maxResults=${maxResults}&interpolation=adaptive&echo=true&brief=false&autoComplete=true&setBack=0&outputSRS=4326&minScore=2&localityName=${localityName}&provinceCode=BC`; | ||
} else if (localityName) { | ||
this.logger.debug(`Calling BC Geocoder with community ${localityName}`); | ||
apiUrl = `${process.env.BC_GEOCODER_API_URL}/addresses.json?locationDescriptor=any&maxResults=${maxResults}&interpolation=adaptive&echo=true&brief=false&autoComplete=true&setBack=0&outputSRS=4326&minScore=2&localityName=${localityName}&provinceCode=BC`; | ||
} else if (addressString && addressString.length > 0) { | ||
this.logger.debug(`Calling BC Geocoder with address ${addressString}`); | ||
apiUrl = `${process.env.BC_GEOCODER_API_URL}/addresses.json?addressString=${addressString}&locationDescriptor=any&maxResults=${maxResults}&interpolation=adaptive&echo=true&brief=false&autoComplete=true&setBack=0&outputSRS=4326&minScore=2&provinceCode=BC`; | ||
} | ||
|
||
if (apiUrl) { | ||
const { data } = await firstValueFrom( | ||
this.httpService.get<any>(apiUrl).pipe( | ||
catchError((error: AxiosError) => { | ||
this.logger.error(error.response); | ||
throw "Error getting BC Geocoder response"; | ||
}) | ||
) | ||
); | ||
return data; | ||
} | ||
} | ||
} |
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