Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

125
Views
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
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!