This repository has been archived by the owner on Apr 19, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
9f645e9
commit de4dd7a
Showing
5 changed files
with
47 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -120,4 +120,8 @@ export interface Configuration { | |
auth: string; | ||
userAgent?: string; | ||
}; | ||
|
||
googleMaps: { | ||
apiKey: string; | ||
}; | ||
} |
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,10 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ConfigModule } from '@nestjs/config'; | ||
import { GoogleMapsService } from './google-maps.service'; | ||
|
||
@Module({ | ||
imports: [ConfigModule], | ||
providers: [GoogleMapsService], | ||
exports: [GoogleMapsService], | ||
}) | ||
export class GoogleMapsModule {} |
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,28 @@ | ||
import { Client } from '@googlemaps/google-maps-services-js'; | ||
import { Injectable, Logger } from '@nestjs/common'; | ||
import { ConfigService } from '@nestjs/config'; | ||
import { Configuration } from '../../config/configuration.interface'; | ||
|
||
@Injectable() | ||
export class GoogleMapsService { | ||
private logger = new Logger(GoogleMapsService.name); | ||
private config = this.configService.get<Configuration['googleMaps']>( | ||
'googleMaps', | ||
); | ||
client: Client; | ||
|
||
constructor(private configService: ConfigService) { | ||
if (this.config.apiKey) this.client = new Client(); | ||
else this.logger.warn('Google Maps API key not found'); | ||
} | ||
|
||
autocomplete(query: string, components?: string[]) { | ||
return this.client.placeAutocomplete({ | ||
params: { | ||
input: query, | ||
key: this.config.apiKey, | ||
components, | ||
}, | ||
}); | ||
} | ||
} |