@@ -8,6 +8,7 @@ interface Ability {
8
8
name : string ;
9
9
description : string ;
10
10
is_hidden : boolean ;
11
+ generation ?: any ;
11
12
}
12
13
13
14
interface Stat {
@@ -31,6 +32,7 @@ export class PokemonDetails {
31
32
public weight : number ,
32
33
public types : string [ ] ,
33
34
public abilities : Ability [ ] ,
35
+ public pastAbilities : Ability [ ] ,
34
36
public superWeakTo : string [ ] ,
35
37
public weakTo : string [ ] ,
36
38
public normal : string [ ] ,
@@ -62,6 +64,26 @@ export class PokemonDetails {
62
64
is_hidden : abilityData . is_hidden ,
63
65
} ;
64
66
} ) ;
67
+ const pastAbilitiesData = Ability [ ]
68
+ data . past_abilities . forEach ( ( pastAbilityData : any ) => {
69
+ const generationName = await getGenerationName ( pastAbilityData . generation ) ;
70
+ pastAbilityData . abilities . forEach ( ( abilityData : any ) => {
71
+ pastAbilitiesData . push ( {
72
+ ability : abilityData . ability ,
73
+ is_hidden : abilityData . is_hidden ,
74
+ generation : generationName ,
75
+ } ) ;
76
+ } ) ;
77
+ } ) ;
78
+ const pastAbilitiesDescriptions = await getAbilitiesDescriptions ( pastAbilitiesData ) ;
79
+ const pastAbilities = pastAbilitiesData . map ( ( abilityData : any , index : number ) => {
80
+ return {
81
+ name : abilityData . ability . name ,
82
+ description : pastAbilitiesDescriptions [ index ] ,
83
+ is_hidden : abilityData . is_hidden ,
84
+ generation : abilityData . generation ,
85
+ } ;
86
+ } ) ;
65
87
const stats = data . stats . map ( ( stat : any ) => {
66
88
return {
67
89
name : stat . stat . name ,
@@ -83,6 +105,7 @@ export class PokemonDetails {
83
105
weight ,
84
106
types ,
85
107
abilities ,
108
+ pastAbilities ,
86
109
damageRelations . superWeakTo ,
87
110
damageRelations . weakTo ,
88
111
damageRelations . normal ,
@@ -114,6 +137,13 @@ export class PokemonDetails {
114
137
return descriptions ;
115
138
}
116
139
140
+ sync function getGenerationName ( generationData : { url : string } ) : Promise < string > {
141
+ const response = await fetch ( generationData . url ) ;
142
+ const data = await response . json ( ) ;
143
+ const englishName = data . names . find ( ( entry : { language : { name : string } } ) => entry . language . name === 'en' ) . name ;
144
+ return englishName ;
145
+ }
146
+
117
147
async function getPokemonDescriptions ( pokemonId : number ) : Promise < DexDescription [ ] > {
118
148
const response = await fetch ( `https://pokeapi.co/api/v2/pokemon-species/${ pokemonId } ` ) ;
119
149
const data = await response . json ( ) ;
0 commit comments