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

171
Views
How to wait for an object to be asynchronously edited?

I have an array of items where I want to append an async value getProductMinQuantity.

The problem is that the render res.status(200)... is sent before item.order_quantity_minimum had been edited.

I thought that a map like below would create a new promise with the items updated.

newResult is a type Promise<any>[] | undefined, I cannot do .then .catch to then execut my res.status in it.

const getCart = async () => {
  
  ...

  let newResult = result.data?.line_items.physical_items.map(async (item: any) =>
    item.order_quantity_minimum = await getProductMinQuantity(item.product_id)
  )

  res.status(200).json({
    data: result.data ? normalizeCart(result.data) : null,
  })
}

Any thought how I can arrange that ?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Classic question; you can't use await inside a synchronous array method (map, forEach, filter etc.). Instead, use a for...of loop.

let newResult = []

for(let item of result.data?.line_items.physical_items) {
  item.order_quantity_minimum = await getProductMinQuantity(item.product_id)
  newResult.push(item);
}

// Do something with newResult
about 4 years ago · Juan Pablo Isaza Report
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!