Is there a way to automate wrapping each child of an object with a function?
// current code
import authController from "./authController";
import appController from "./appController";
import userController from "./userController";
import postController from "./postController";
import { executeRequest } from "./utils";
const controllers = {
user: { save: executeRequest(userController.save),
confirm: executeRequest(userController.confirm) },
post: {
save: executeRequest(postController.save),
},
auth: {
signin: executeRequest(authController.signin),
signout: executeRequest(authController.signout)
},
app: {
get: executeRequest(appController.get)
}
I am looking for a solution that would allow me to use the object in the following format:
// expectation
import authController from "./authController";
import appController from "./appController";
import userController from "./userController";
import postController from "./postController";
import { executeRequest } from "./utils";
// do something here to wrap the children
const controllers = {
user: userController,
auth: authController,
post: postController,
app: appController
};
import controllers from "../controllers";
const postController = controllers.post;
router.post(Routes.DEFAULT, postController.save);
Thank you!