Skip to content

Commit

Permalink
fix(sanity): now returning null from getPlayer when a name is passed …
Browse files Browse the repository at this point in the history
…in and doesn't match a player

this bug was found in testing before production
  • Loading branch information
KenEucker committed Dec 28, 2023
1 parent 4a9e53b commit f0c290e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
11 changes: 6 additions & 5 deletions examples/node/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
8 changes: 7 additions & 1 deletion src/sanity/getPlayers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit f0c290e

Please sign in to comment.