This repository was archived by the owner on Apr 19, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 5 files changed +47
-0
lines changed Expand file tree Collapse file tree 5 files changed +47
-0
lines changed Original file line number Diff line number Diff line change @@ -35,6 +35,7 @@ import { ElasticSearchModule } from './providers/elasticsearch/elasticsearch.mod
35
35
import { FirebaseModule } from './providers/firebase/firebase.module' ;
36
36
import { GeolocationModule } from './providers/geolocation/geolocation.module' ;
37
37
import { GitHubModule } from './providers/github/github.module' ;
38
+ import { GoogleMapsModule } from './providers/google-maps/google-maps.module' ;
38
39
import { MailModule } from './providers/mail/mail.module' ;
39
40
import { PrismaModule } from './providers/prisma/prisma.module' ;
40
41
import { S3Module } from './providers/s3/s3.module' ;
@@ -76,6 +77,7 @@ import { TasksModule } from './providers/tasks/tasks.module';
76
77
CloudinaryModule ,
77
78
FirebaseModule ,
78
79
GitHubModule ,
80
+ GoogleMapsModule ,
79
81
] ,
80
82
providers : [
81
83
{
Original file line number Diff line number Diff line change @@ -120,4 +120,8 @@ export interface Configuration {
120
120
auth : string ;
121
121
userAgent ?: string ;
122
122
} ;
123
+
124
+ googleMaps : {
125
+ apiKey : string ;
126
+ } ;
123
127
}
Original file line number Diff line number Diff line change @@ -133,6 +133,9 @@ const configuration: Configuration = {
133
133
auth : process . env . GITHUB_AUTH ,
134
134
userAgent : process . env . GITHUB_USER_AGENT ,
135
135
} ,
136
+ googleMaps : {
137
+ apiKey : process . env . GOOGLE_MAPS_API_KEY ,
138
+ } ,
136
139
} ;
137
140
138
141
const configFunction : ConfigFactory < Configuration > = ( ) => configuration ;
Original file line number Diff line number Diff line change
1
+ import { Module } from '@nestjs/common' ;
2
+ import { ConfigModule } from '@nestjs/config' ;
3
+ import { GoogleMapsService } from './google-maps.service' ;
4
+
5
+ @Module ( {
6
+ imports : [ ConfigModule ] ,
7
+ providers : [ GoogleMapsService ] ,
8
+ exports : [ GoogleMapsService ] ,
9
+ } )
10
+ export class GoogleMapsModule { }
Original file line number Diff line number Diff line change
1
+ import { Client } from '@googlemaps/google-maps-services-js' ;
2
+ import { Injectable , Logger } from '@nestjs/common' ;
3
+ import { ConfigService } from '@nestjs/config' ;
4
+ import { Configuration } from '../../config/configuration.interface' ;
5
+
6
+ @Injectable ( )
7
+ export class GoogleMapsService {
8
+ private logger = new Logger ( GoogleMapsService . name ) ;
9
+ private config = this . configService . get < Configuration [ 'googleMaps' ] > (
10
+ 'googleMaps' ,
11
+ ) ;
12
+ client : Client ;
13
+
14
+ constructor ( private configService : ConfigService ) {
15
+ if ( this . config . apiKey ) this . client = new Client ( ) ;
16
+ else this . logger . warn ( 'Google Maps API key not found' ) ;
17
+ }
18
+
19
+ autocomplete ( query : string , components ?: string [ ] ) {
20
+ return this . client . placeAutocomplete ( {
21
+ params : {
22
+ input : query ,
23
+ key : this . config . apiKey ,
24
+ components,
25
+ } ,
26
+ } ) ;
27
+ }
28
+ }
You can’t perform that action at this time.
0 commit comments