how would you access functions within a controller that are contained within a parent function? In the example below, I am unable to access the getConfig()
function.
The reason I have it setup in this manner is so that I can still access the Fastify instance in the controller.
route.js
import formbody from '@fastify/formbody'
import controller from '../../controllers/controller.js'
const routes = (fastify, options, done) => {
fastify.register(formbody)
fastify.register(controller)
fastify.get('/get-config', (req, rep) => {
getConfig(req, rep)
})
}
export default routes
controller.js
import merchant from '../models/merchant.js'
const controller = (fastify, options, done) => {
const srvcMerchant = new merchant(fastify)
const getConfig = async (req, rep) => {
const config = await srvcMerchant.getConfig(req.id);
if (!config) {
return rep
.status(404)
.send({ message: 'Not found' })
}
rep.send(config);
}
}
export default controller