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

Commit

Permalink
✨ Add Google Maps module
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 14, 2020
1 parent 9f645e9 commit de4dd7a
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import { ElasticSearchModule } from './providers/elasticsearch/elasticsearch.mod
import { FirebaseModule } from './providers/firebase/firebase.module';
import { GeolocationModule } from './providers/geolocation/geolocation.module';
import { GitHubModule } from './providers/github/github.module';
import { GoogleMapsModule } from './providers/google-maps/google-maps.module';
import { MailModule } from './providers/mail/mail.module';
import { PrismaModule } from './providers/prisma/prisma.module';
import { S3Module } from './providers/s3/s3.module';
Expand Down Expand Up @@ -76,6 +77,7 @@ import { TasksModule } from './providers/tasks/tasks.module';
CloudinaryModule,
FirebaseModule,
GitHubModule,
GoogleMapsModule,
],
providers: [
{
Expand Down
4 changes: 4 additions & 0 deletions src/config/configuration.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,4 +120,8 @@ export interface Configuration {
auth: string;
userAgent?: string;
};

googleMaps: {
apiKey: string;
};
}
3 changes: 3 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@ const configuration: Configuration = {
auth: process.env.GITHUB_AUTH,
userAgent: process.env.GITHUB_USER_AGENT,
},
googleMaps: {
apiKey: process.env.GOOGLE_MAPS_API_KEY,
},
};

const configFunction: ConfigFactory<Configuration> = () => configuration;
Expand Down
10 changes: 10 additions & 0 deletions src/providers/google-maps/google-maps.module.ts
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 {}
28 changes: 28 additions & 0 deletions src/providers/google-maps/google-maps.service.ts
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,
},
});
}
}

0 comments on commit de4dd7a

Please sign in to comment.