Last active
April 6, 2020 09:01
-
-
Save zaslavskij/8562b69b5d98c54d483a37891d651441 to your computer and use it in GitHub Desktop.
7-7.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (planetId) => { | |
| const planetLink = `https://swapi.co/api/planets/${planetId}/?format=json`; | |
| const getPlanet = (link) => axios.get(link).then((it) => it.data); | |
| const getFilms = (filmsLinksArr) => Promise.all(filmsLinksArr.map(filmUrl => axios.get(filmUrl))).then(films => films.map(film => film.data)); | |
| return new Promise(resolve => { | |
| getPlanet(planetLink).then(planet => { | |
| getFilms(planet.films).then(filmsArr => { | |
| return Promise.all( | |
| filmsArr.map(film => { | |
| return Promise.all( | |
| film.species.map(specie => axios(specie).then(it => it.data)) | |
| ).then(response => resolve({ | |
| ...planet, | |
| films: filmsArr, | |
| species: response | |
| })); | |
| }) | |
| ) | |
| }); | |
| }); | |
| }) | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment