Add FocoLive events route
This commit is contained in:
@@ -21,6 +21,7 @@ import { RedisClientOptions } from 'redis';
|
||||
import { redisStore } from 'cache-manager-redis-yet';
|
||||
import { RedirectsModule } from './redirects/redirects.module';
|
||||
import { FileModule } from './file/file.module';
|
||||
import { FocoLiveModule } from './foco-live/foco-live.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
@@ -76,6 +77,7 @@ import { FileModule } from './file/file.module';
|
||||
KvModule,
|
||||
RedirectsModule,
|
||||
FileModule,
|
||||
FocoLiveModule,
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
|
@@ -28,5 +28,10 @@ export default () => ({
|
||||
bucketName: process.env.FILE_BUCKET_NAME ?? process.env.S3_BUCKET ?? 'api.us.dev-files',
|
||||
// default file ttl in seconds
|
||||
defaultTtl: parseInt(process.env.FILE_DEFAULT_TTL ?? (30 * 24 * 60 * 60).toString()),
|
||||
},
|
||||
focoLive: {
|
||||
airtable: {
|
||||
apiKey: process.env.FOCO_LIVE_AIRTABLE_APIKEY ?? '',
|
||||
}
|
||||
}
|
||||
});
|
||||
|
16
src/foco-live/foco-live.controller.ts
Normal file
16
src/foco-live/foco-live.controller.ts
Normal file
@@ -0,0 +1,16 @@
|
||||
import { Controller, Get } from '@nestjs/common';
|
||||
import { FocoLiveService } from './foco-live.service';
|
||||
import { ApiTags } from '@nestjs/swagger';
|
||||
|
||||
@ApiTags('foco-live')
|
||||
@Controller('foco-live')
|
||||
export class FocoLiveController {
|
||||
constructor(
|
||||
private readonly focoLiveService: FocoLiveService,
|
||||
) { }
|
||||
|
||||
@Get('events')
|
||||
async getEvents() {
|
||||
return this.focoLiveService.getEvents();
|
||||
}
|
||||
}
|
9
src/foco-live/foco-live.module.ts
Normal file
9
src/foco-live/foco-live.module.ts
Normal file
@@ -0,0 +1,9 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { FocoLiveController } from './foco-live.controller';
|
||||
import { FocoLiveService } from './foco-live.service';
|
||||
|
||||
@Module({
|
||||
controllers: [FocoLiveController],
|
||||
providers: [FocoLiveService]
|
||||
})
|
||||
export class FocoLiveModule {}
|
33
src/foco-live/foco-live.service.ts
Normal file
33
src/foco-live/foco-live.service.ts
Normal file
@@ -0,0 +1,33 @@
|
||||
import { Injectable } from '@nestjs/common';
|
||||
import { ConfigService } from '@nestjs/config';
|
||||
import * as Airtable from 'airtable';
|
||||
import { AirtableBase } from 'airtable/lib/airtable_base';
|
||||
|
||||
const tables = {
|
||||
venues: 'tblRi4wDorKqNJJbs',
|
||||
events: 'tbl4RZ75QF5WefE7L',
|
||||
}
|
||||
|
||||
const compareDates = (a: any, b: any) => new Date(a.Date).getTime() - new Date(b.Date).getTime();
|
||||
|
||||
@Injectable()
|
||||
export class FocoLiveService {
|
||||
private readonly airtableBase: AirtableBase;
|
||||
|
||||
constructor(
|
||||
private readonly config: ConfigService,
|
||||
) {
|
||||
this.airtableBase = new Airtable({
|
||||
apiKey: config.get('focoLive.airtable.apiKey'),
|
||||
}).base('app1SjPrn5qrhr59J');
|
||||
}
|
||||
|
||||
async getEvents() {
|
||||
return (await this.airtableBase('Events').select({
|
||||
view: "Grid view",
|
||||
}).all())
|
||||
.map(record => record.fields)
|
||||
.sort(compareDates)
|
||||
.reverse();
|
||||
}
|
||||
}
|
@@ -1,7 +1,8 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { RedirectsController } from './redirects.controller';
|
||||
import { RequiredReadingController } from './required-reading.controller';
|
||||
|
||||
@Module({
|
||||
controllers: [RedirectsController]
|
||||
controllers: [RedirectsController, RequiredReadingController]
|
||||
})
|
||||
export class RedirectsModule {}
|
||||
export class RedirectsModule { }
|
||||
|
Reference in New Issue
Block a user