Answer the question
In order to leave comments, you need to log in
How to make nested asynchronous requests?
Hello.
At first glance, the task seemed simple to me, but I have been sitting on it for 2 hours.
I write rest api on node js.
There is a router (express) that takes 2 parameters in the request field (query params) ->
http://localhost:5000/api/item/?title=new task&user_id=1
router.get('/', async (req, res) => {
const {title,user_id} = req.query
})
router.get('/', async (req, res) => {
const {title,user_id} = req.query
const items = await Item.findAll({ where: { title, user_id } })
})
let result = await items.map(async (item) => {
const { title, phone, name, email } = await User.findByPk(item.user_id)
return {
id: item.id,
title: item.title,
price: item.price,
image: item.image,
createdAt: item.createdAt,
user: { title, phone, name, email }
}
})
res.json({ valid: true, data: result })
"data": [
{}
]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question