gdirk07 / PokemonChecker

Playing around with APIs
https://gdirk07.github.io/PokemonChecker/
0 stars 0 forks source link

Convert the PokemonDTO's pokemonAbilities from [] -> {} #121

Closed jeremy-jtlo closed 3 months ago

jeremy-jtlo commented 3 months ago

Ran into an issue serializing/de-serializing pokemonDTO data.

Basically, when trying to understand what abilities a pokemon has, it would always come back in a list. For example, Bulbasaur's abilities were stored as so:

bulbasaur.abilities [Array(2), Array(2)]

There were 2 issues with this, the first being that the raw arrays didn't have any key information until digging into them by a layer: bulbasaur.abilities[0][0].name -> how to fetch the name "overgrow" bulbasaur.abilities[1][0].name -> how to fetch the name "chlorophyll" While the second issue was that the isHidden property was not labeled. It was just the second element of the array.

bulbasaur.abilities[0][1] -> false -> indicates that "overgrow" is not a hidden ability. bulbasaur.abilities[1][1] -> true -> indicates that "chlorophyll" is a hidden ability.

The new method has abilities stored instead as objects. Now when we fetch this info, the ability and isHidden property are labeled.

bulbasaur.abilities[0].ability.name -> "overgrow" bulbasaur.abilities[0].isHidden -> false

Should help clarify things when working with DTO data that's cached or stored elsewhere.