Add FocoLive events route

This commit is contained in:
2024-03-25 22:30:57 -06:00
parent 7bdb45da45
commit 20caec034f
9 changed files with 110 additions and 2 deletions

View File

@@ -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],

View File

@@ -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 ?? '',
}
}
});

View 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();
}
}

View 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 {}

View 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();
}
}

View File

@@ -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 { }