Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

127
Vistas
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 la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda