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

Commit

Permalink
✨ Add Airtable module
Browse files Browse the repository at this point in the history
  • Loading branch information
AnandChowdhary committed Nov 13, 2020
1 parent 7ac9b06 commit bd930be
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import { SessionsModule } from './modules/sessions/sessions.module';
import { StripeModule } from './modules/stripe/stripe.module';
import { UsersModule } from './modules/users/users.module';
import { WebhooksModule } from './modules/webhooks/webhooks.module';
import { AirtableModule } from './providers/airtable/airtable.module';
import { DnsModule } from './providers/dns/dns.module';
import { ElasticSearchModule } from './providers/elasticsearch/elasticsearch.module';
import { GeolocationModule } from './providers/geolocation/geolocation.module';
Expand Down Expand Up @@ -66,6 +67,7 @@ import { TasksModule } from './providers/tasks/tasks.module';
WebhooksModule,
ElasticSearchModule,
SlackModule,
AirtableModule,
],
providers: [
{
Expand Down
5 changes: 5 additions & 0 deletions src/config/configuration.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,4 +91,9 @@ export interface Configuration {
rejectRateLimitedCalls?: boolean;
retries: number;
};

airtable: {
apiKey: string;
endpointUrl?: string;
};
}
4 changes: 4 additions & 0 deletions src/config/configuration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,10 @@ const configuration: Configuration = {
rejectRateLimitedCalls: !!process.env.SLACK_REJECT_RATE_LIMITED_CALLS,
retries: int(process.env.SLACK_FAIL_RETRIES, 3),
},
airtable: {
apiKey: process.env.AIRTABLE_API_KEY ?? '',
endpointUrl: process.env.AIRTABLE_ENDPOINT_URL,
},
};

const configFunction: ConfigFactory<Configuration> = () => configuration;
Expand Down
10 changes: 10 additions & 0 deletions src/providers/airtable/airtable.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 { AirtableService } from './airtable.service';

@Module({
imports: [ConfigModule],
providers: [AirtableService],
exports: [AirtableService],
})
export class AirtableModule {}
22 changes: 22 additions & 0 deletions src/providers/airtable/airtable.service.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { Injectable, Logger } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import Airtable from 'airtable';
import { Configuration } from '../../config/configuration.interface';

@Injectable()
export class AirtableService {
airtable?: Airtable;
private logger = new Logger(AirtableService.name);

constructor(private configService: ConfigService) {
const config = this.configService.get<Configuration['airtable']>(
'airtable',
);
if (config.apiKey)
this.airtable = new Airtable({
apiKey: config.apiKey,
endpointUrl: config.endpointUrl,
});
else this.logger.warn('No Airtable API key set');
}
}
4 changes: 2 additions & 2 deletions src/providers/slack/slack.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Configuration } from '../../config/configuration.interface';

@Injectable()
export class SlackService {
slack: WebClient;
slack?: WebClient;
private logger = new Logger(SlackService.name);
private queue = new PQueue({ concurrency: 1 });

Expand Down Expand Up @@ -38,6 +38,6 @@ export class SlackService {
}

private async sendMessage(options: ChatPostMessageArguments) {
return this.slack.chat.postMessage(options);
return this.slack?.chat.postMessage(options);
}
}

0 comments on commit bd930be

Please sign in to comment.