Skip to content
This repository was archived by the owner on Apr 19, 2023. It is now read-only.

Commit de4dd7a

Browse files
✨ Add Google Maps module
1 parent 9f645e9 commit de4dd7a

File tree

5 files changed

+47
-0
lines changed

5 files changed

+47
-0
lines changed

src/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import { ElasticSearchModule } from './providers/elasticsearch/elasticsearch.mod
3535
import { FirebaseModule } from './providers/firebase/firebase.module';
3636
import { GeolocationModule } from './providers/geolocation/geolocation.module';
3737
import { GitHubModule } from './providers/github/github.module';
38+
import { GoogleMapsModule } from './providers/google-maps/google-maps.module';
3839
import { MailModule } from './providers/mail/mail.module';
3940
import { PrismaModule } from './providers/prisma/prisma.module';
4041
import { S3Module } from './providers/s3/s3.module';
@@ -76,6 +77,7 @@ import { TasksModule } from './providers/tasks/tasks.module';
7677
CloudinaryModule,
7778
FirebaseModule,
7879
GitHubModule,
80+
GoogleMapsModule,
7981
],
8082
providers: [
8183
{

src/config/configuration.interface.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,4 +120,8 @@ export interface Configuration {
120120
auth: string;
121121
userAgent?: string;
122122
};
123+
124+
googleMaps: {
125+
apiKey: string;
126+
};
123127
}

src/config/configuration.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ const configuration: Configuration = {
133133
auth: process.env.GITHUB_AUTH,
134134
userAgent: process.env.GITHUB_USER_AGENT,
135135
},
136+
googleMaps: {
137+
apiKey: process.env.GOOGLE_MAPS_API_KEY,
138+
},
136139
};
137140

138141
const configFunction: ConfigFactory<Configuration> = () => configuration;
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
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 {}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}

0 commit comments

Comments
 (0)