I typically make several .get requests, such as the following for notesController
controller.get('/customers/', async (req, res, next) => {
const customers = await Customer.find();
res.status(200).send(customers);
});
controller.get('/documents/', async (req, res, next) => {
const orders = await Order.find();
res.status(200).send(orders);
});
Sometimes, I need to call both of them simultaneously like this:
controller.get('/version/', async (req, res, next) => {
const ver = await Version.findById(req.headers.sub);
if (req.headers.dbversion === ver.dbversion) {
res.status(200).send({ versionMatch: true });
} else {
req.url = '/customers/';
const custData = await controller.handle(req, res, next);
req.url = '/orders/';
const orders = await controller.handle(req, res, next);
res.status(200).send({ customers: custData, docs: invoices });
}
});
Unfortunately, this approach does not work. Even though I can see from a console message that my .get('/customers') function is being called, it does not return any data. My goal is to be able to make one API call and receive both sets of data if certain conditions are met. How can I best achieve this?