Closed otaviobonder-deel closed 5 years ago
I think the simple answer is move the functionality out of your middleware functions and then call them from one or both middleware. For example:
async function listInvoices () {
// ...
}
app.get('/invoices', await (req, res) => {
try {
const invoices = await listInvoices()
return res.json(invoices);
} catch (error) {
return res.status(400).send({ error });
}
})
app.get('/match', await (req, res) => {
try {
const invoices = await listInvoices()
// ...
} catch (error) { }
})
If you have further questions I would post on Stack Overflow or in the Express gitter as opposed to here. This is more for bugs and feature development for Express, not support requests. Good luck!
Hi there, I searched the web but I can't find the answer to my question.
I have these express functions:
They have different routes, and I can call them. However, I want the
matchTransactions
function to calllistInvoices
andlistBankTransactions
and store their responses in variables, so I can manipulate these data and then return thematchTransactions
response.The way my code is right now,
listBankTransactions
returns the response instead of storing in transactions constant, and then there is an exception on thelistInvoices
response, because the response was already returned bylistBankTransactions
.What's the best way to achieve what I'm looking for?
Thanks in advance!