I’m querying a third party API (ESPN Fantasy) from my front end to clean the data and use it in my app. While adding new data details, I have an issue : when trying to apply detailed raters to my players, I end up getting wrong values. So I logged the data during the process and I get this weird result :
The first object is the raw data from the third party API, with the correct values. The second object is what I get when I parse them. As you can see, the collapsed version of my object has the correct values but the expanded version has wrong values. Those wrong values are the one I end up with in my app.
Here is the code where I parse the data :
const basePlayerRaters: PlayerCategoriesRaters = {
[StatsCategories.FG]: 0,
[StatsCategories.FT]: 0,
[StatsCategories["3PM"]]: 0,
[StatsCategories.REB]: 0,
[StatsCategories.AST]: 0,
[StatsCategories.STL]: 0,
[StatsCategories.BLK]: 0,
[StatsCategories.TO]: 0,
[StatsCategories.PTS]: 0,
};
const buildPlayerRaters = (
rawRater: PlayerRatings | undefined
): PlayerCategoriesRaters => {
const output = basePlayerRaters;
if (rawRater) {
rawRater.statRankings.forEach((value) => {
const key = RaterCategories.get(value.forStat);
if (key) {
output[key] = value.rating;
}
});
}
console.log("build raters 2 : ", rawRater, output);
return output;
};
I don’t understand where these wrong values come from, why I get them and, out of curiosity, why the console.log has both the good and bad data.
