Advertisement
Guest User

Untitled

a guest
Apr 29th, 2022
34
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. app.get('/', (req, res) => {
  2.     let gamesArr = [];
  3.     axios.get('api1.com/sale')
  4.         .then((response) => {
  5.             gamesArr = response.data.game_discounts; //De este array extraigo un ID que lo paso a la api2
  6.         })
  7.         .catch((error) => {
  8.             console.log(error);
  9.         })
  10.     let openCriticId = [];
  11.     for (let i of gamesArr) {
  12.         if (i.OpenCriticID !== '0' && i.OpenCriticID !== '-1' && i.OpenCriticID !== '-2') {
  13.             axios.get(`https://api.opencritic.com/api/game/${i.OpenCriticID}`)
  14.                 .then((response) => {
  15.                     openCriticId = [response.data.name, response.data.medianScore];
  16.                 })
  17.                 .catch((error) => {
  18.                     console.log(error);
  19.                 })
  20.         }
  21.     }
  22.     console.log(openCriticId); //Este es el array que se retorna vacio
  23.     res.render('inicio', { gamesArr, openCriticId })
  24. })
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement