From a8ba435ec3cc2c53c06ed09e7b479ad8fc1340da Mon Sep 17 00:00:00 2001 From: Chip Wasson Date: Tue, 14 May 2024 18:41:50 -0600 Subject: [PATCH] Add venues --- src/foco-live/foco-live.controller.ts | 6 ++++++ src/foco-live/foco-live.service.ts | 30 +++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/src/foco-live/foco-live.controller.ts b/src/foco-live/foco-live.controller.ts index c3bf548..4cb2bb9 100644 --- a/src/foco-live/foco-live.controller.ts +++ b/src/foco-live/foco-live.controller.ts @@ -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(); + } } diff --git a/src/foco-live/foco-live.service.ts b/src/foco-live/foco-live.service.ts index f3126d4..54871c1 100644 --- a/src/foco-live/foco-live.service.ts +++ b/src/foco-live/foco-live.service.ts @@ -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 { + return ((await this.airtableBase('Venues').select({ + view: "Grid view", + }).all()) + .map(record => record.fields) as any as Venue[]) + .sort(compareDates) + .reverse(); + } + + async getAllVenuesCached(): Promise { + return await this.cacheManager.get(cacheKeys.allVenues) || await this.getAllVenues(); + } + @Cron("0 */5 * * * *") async refreshEvents() { this.logger.verbose("Refreshing events cache.");