Add venues

This commit is contained in:
2024-05-14 18:41:50 -06:00
parent 13096102bc
commit a8ba435ec3
2 changed files with 36 additions and 0 deletions

View File

@@ -23,4 +23,10 @@ export class FocoLiveController {
this.logger.verbose(`GET /foco-live/events?venue=${venue}&before=${before}&after=${after}`);
return this.focoLiveService.getEvents({ venue, before: before ? new Date(before) : undefined, after: after ? new Date(after) : undefined });
}
@Get('venues')
async getVenues() {
this.queryCount.inc();
return this.focoLiveService.getAllVenuesCached();
}
}

View File

@@ -5,6 +5,7 @@ import { Cron } from '@nestjs/schedule';
import { InjectMetric } from '@willsoto/nestjs-prometheus';
import * as Airtable from 'airtable';
import { AirtableBase } from 'airtable/lib/airtable_base';
import { all } from 'axios';
import { Cache } from 'cache-manager';
import { Gauge } from 'prom-client';
import { filter, pipe } from 'ramda';
@@ -29,8 +30,24 @@ export interface Event {
"Date Select": string
}
export interface Venue {
"Bar or Venue Name": string,
"Street Address": string,
"City": string,
"Zip Code": number,
State: string,
"Phone Number": string,
Website: string,
"Has Calendar Of Events": string,
"Facebook Page": string,
"Instagram": string,
"Twitter Account": string,
}
const cacheKeys = {
allEvents: 'foco_live_events',
allVenues: 'foco_live_venues',
}
@Injectable()
@@ -69,6 +86,19 @@ export class FocoLiveService {
return events;
}
async getAllVenues(): Promise<Venue[]> {
return ((await this.airtableBase('Venues').select({
view: "Grid view",
}).all())
.map(record => record.fields) as any as Venue[])
.sort(compareDates)
.reverse();
}
async getAllVenuesCached(): Promise<Venue[]> {
return await this.cacheManager.get(cacheKeys.allVenues) || await this.getAllVenues();
}
@Cron("0 */5 * * * *")
async refreshEvents() {
this.logger.verbose("Refreshing events cache.");