I have the following routes defined
router.get('/:company', function (req, res, next) {
// 1. call database and get company data
// 2. render company view
})
router.get('/:company/employees', function (req, res, next) {
// 1. call database and get company data
// 2. call database and get employees data
// 3. render employees view
})
How can I merge these 2 routes to make only one call to the database to get company data. Basically I just want to reuse that logic.
I´m looking for something like this (tested but it doesn't work)
router.get('/:company', function (req, res, next) {
// 1. call database and get company data
// 2. render company view
router.get('/:company/employees', function (req, res, next) {
// no need to call database to get company data. we already have it
// 1. call database and get employees data
// 2. render employees view
})
})