From 0cefa9b139bf23780ed0b464b4a9148116c79ea4 Mon Sep 17 00:00:00 2001 From: Alec Lomas Date: Wed, 16 Feb 2022 00:03:52 -0800 Subject: [PATCH] :recycle: return unique place count --- graphql/resolvers/places.ts | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/graphql/resolvers/places.ts b/graphql/resolvers/places.ts index 131abb0..67f267d 100644 --- a/graphql/resolvers/places.ts +++ b/graphql/resolvers/places.ts @@ -1,6 +1,12 @@ import fetch from '../lib/fetchWithTimeout' import { thirtyDaysAgo } from '../lib/date' +type Checkin = { + venue: { + id: string + } +} + const getPlaces = async (): Promise => { const uri = `https://api.foursquare.com/v2/users/self/checkins?oauth_token=${ process.env.FOURSQUARE_KEY @@ -18,7 +24,13 @@ const getPlaces = async (): Promise => { let places = null if (Object.keys(data.response).length !== 0) { - places = data.response.checkins.items.length + const venueIds = data.response.checkins.items.map( + (checkin: Checkin) => checkin.venue.id + ) + + const uniqueVenueIds = new Set(venueIds) + + places = uniqueVenueIds.size } return places -- 2.51.2