Good morning, I have a web application made in Nodejs, in one of the requests I must send data of different models. My query is as follows Is this the correct way?
function getProduct (req, res) {
let productId = req.params.productId
Product.findById(productId, (err, product) => {
if (err) return res.status(500).send({message: 'Error al realizar la petición: ${err}'})
if (!product) return res.status(404).send({message: 'No existen productos'})
Company.find({}, (err, companies) => {
if (err) return res.status(500).send({message: 'Error al realizar la petición: ${err}'})
if (!companies) return res.status(404).send({message: 'No existen compañias'})
res.status(200).send({product: product, companies: companies})
})
})
}