Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

129
Visualizações
API Routes returning data in different structures, I need an array of objects returned

Currently my Api is returning an object instead of an object within an array, however I can't seem to tell the difference between these two routes and why one would return said array of data over the other. I can't seem to spot the difference here, unless it has something to do with using the Op.like ORM?
For instance :

router.get('/caseDetail/:id', (req,res) => {
db.caseDetail.findOne({
    include : [db.Part,db.Fault,db.Disposition,db.Contact,db.Site]
}).then((response) => {
    res.json(response);
}).catch((error) => {
    console.table([stack.error,stack.id,error])
})
})

The above route returns an array of data while the following returns just an object

router.get('/caseDetail/:caseName', (req,res) => {
    db.caseDetail.findAll({
        
        include : [db.Part,db.Fault,db.Disposition,db.Contact,db.Site],
        where : {
            caseName:{ 
              [Op.like]: req.params.caseName}
        }
    }).then((response) => {
        console.log(response);
        res.json(response)
    }).catch((error) => {
        console.log(error);
    })
})

-------------------------- For context----------------------------
I've enacted this method multiple times, even in other script files, but I haven't been required to parse data in this manner, is something out of shape here that im over looking? Am I missing a JSON.parse(); here? Github

  try { 
                  const items = await axios.get(`/api/caseDetail/:caseName` + caseName);
                console.log(items.data); 
                $tbody.empty()
                items.data.forEach((item) => {
                    console.log(item);

Returned Results

{id: 2, caseName: "1 - Fenway Park - 1", createdAt: "2021-07-27T18:13:55.000Z", updatedAt: "2021-07-27T18:13:55.000Z", UserId: 1, …}

Error Message

TypeError: items.data.forEach is not a function
    at callSearchResults (searchInventory.js:29)
about 4 years ago · Juan Pablo Isaza
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda