How to consume two endpoints with Axios and increment a list with the return of the second endpoint?

Asked

Viewed 16 times

0

Guys I have the following method in my project with Vue.js:

      var lista = []
      axios.get(this.$store.state.baseUrlAtendSac + 'AtendSacAtendente/ListarAtendSacAtendente', this.dadosLoginSession.fccTokenHeaders)
        .then(response => {
          this.listaAtendentes = response.data
          lista.push(response.data)
          if (this.listaAtendentes.length > 0) {
            for (var i = 0; i < this.listaAtendentes.length; i++) {
              this.listaAtendenteNovas.push(this.listaAtendentes[i])
              var objListaimagem = []
              axios.get(this.$store.state.baseUrlSga + 'File/DownloadIdExt?idExt=' + this.listaAtendentes[i].usuId + '&codArqCad=AFU', this.dadosLoginSession.fccTokenHeaders)
                .then(response => {
                  objListaimagem.push(response.data)
                })
            }
            var novo = [].concat(lista, objListaimagem)
            console.log(JSON.stringify(novo))
          }
        })
        .catch(error => {
          this.setErrorSystem(error)
        })
    },

No this.listText it returns that list:

   {
      "idAtendente":2,
      "usuId":"vovozinho",
      "idArquivo":1358,
      "cdFuncionario":0,
      "valid":false,
      "lista":[
         
      ]
   },
   {
      "idAtendente":3,
      "usuId":"jjoao",
      "idArquivo":1362,
      "cdFuncionario":0,
      "valid":false,
      "lista":[
         
      ]
   }
]

now in the image objListaimagem it returns this object:

[
   {
      "arqid":1352,
      "repoid":10,
      "arqcadid":22,
      "arqchaverepositorio":"92",
      "arqnomeoriginalarquivo":"atela.PNG",
      "arqextensao":".PNG",
      "arqtamanhokb":"1137426",
      "arqmetadata":null,
      "arqlinkext":"DESENV/",
      "arqpublico":true,
      "arqdatacriacao":"2020-12-22T11:37:21.16",
      "arqdataexclusao":null,
      "arqmimetype":null,
      "arqnomearquivo":"92.PNG",
      "arqidexterno":"vovozinho",
      "arqcadcodigo":"AFU",
      "arqrepoorigem":null,
      "arqrepodestino":null,
      "arqseqrepositorio":92,
      "arqurl":"http://cdn.teste.com.br/DESENV//92.PNG",
      "mensagem":null
   }
]

I need to take the penultimate property of the above object (arqurl) and add it to the object of the list corresponding to the last parameter, so that the first list (this.listAtents) looks like this for each object:

{
      "idAtendente":2,
      "usuId":"vovozinho",
      "idArquivo":1358,
      "cdFuncionario":0,
      "valid":false,
      "lista":[],
      "arqurl":"http://teste.com.br/DESENV//92.PNG", <------- item adicionado
 }
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.