From f0c290eb1021bcc00447acfe925b1d675e96e05d Mon Sep 17 00:00:00 2001 From: Ken Eucker Date: Thu, 28 Dec 2023 12:19:37 -0800 Subject: [PATCH] fix(sanity): now returning null from getPlayer when a name is passed in and doesn't match a player this bug was found in testing before production --- examples/node/index.js | 11 ++++++----- src/sanity/getPlayers.ts | 8 +++++++- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/examples/node/index.js b/examples/node/index.js index 00409e4..3808d6a 100644 --- a/examples/node/index.js +++ b/examples/node/index.js @@ -130,7 +130,7 @@ const getAllGamesAsync = async (pre, client, out = false, opts = {}) => { const get1PlayerAsync = async (pre, client, out = false, opts = {}) => { opts.limit = opts.limit ? opts.limit : 10 - const testPlayerData = await client.getPlayer('player-test', opts).catch(console.error) + const testPlayerData = await client.getPlayer('Ken', opts).catch(console.error) log(`${pre} :: success fully retrieved player data`, testPlayerData, out) return testPlayerData @@ -188,7 +188,8 @@ const runTests = async (out = false) => { await get10PlayersAsync("BikeTag", biketagDefaultInstance, out) } - if (bikeTagImgurInstance) { + if (false) { + // if (bikeTagImgurInstance) { console.log(pretty("Imgur BikeTag Client Instantiated"), imgurInstanceOpts) await getGameAsync("Imgur", bikeTagImgurInstance, out) // await getTag1Async("Imgur", bikeTagImgurInstance, out) @@ -206,9 +207,9 @@ const runTests = async (out = false) => { // await get10TagsAsync("Sanity", bikeTagSanityInstance, out) await getGameAsync("Sanity", bikeTagSanityInstance, out) // await getAllGamesAsync("Sanity", bikeTagSanityInstance, out) - await get10PlayersAsync("Sanity", bikeTagSanityInstance, out) - // await get1PlayerAsync("Sanity", bikeTagSanityInstance, out) - await get10AchievementsAsync("Sanity", bikeTagSanityInstance, out) + // await get10PlayersAsync("Sanity", bikeTagSanityInstance, out) + await get1PlayerAsync("Sanity", bikeTagSanityInstance, out) + // await get10AchievementsAsync("Sanity", bikeTagSanityInstance, out) // await get10AmbassadorsAsync("Sanity", bikeTagSanityInstance, out) // await get10SettingsAsync("Sanity", bikeTagSanityInstance, out) // await get10AchievementsAsync("Sanity", bikeTagSanityInstance, out) diff --git a/src/sanity/getPlayers.ts b/src/sanity/getPlayers.ts index 10ce995..4f0846d 100644 --- a/src/sanity/getPlayers.ts +++ b/src/sanity/getPlayers.ts @@ -30,10 +30,16 @@ export async function getPlayers( ) return client.fetch(query, {}).then((players) => { - const playersData = players.map((player: any) => + let playersData = players.map((player: any) => constructPlayerFromSanityObject(player, fieldsFilter) ) + if (payload.slugs?.length) { + playersData = playersData.filter((p) => payload.slugs?.includes(p.slug)) + } else if (payload.names?.length) { + playersData = playersData.filter((p) => payload.names?.includes(p.name)) + } + const response = { data: sortPlayers(playersData, payload.sort, payload.limit), status: HttpStatusCode.Found,