I'm using express nodejs, in my project, one scenario occurred while doing work on a specific module. I have made different functions for different roles, so based on the logged-in user's role, dynamically calling the other function. I want a trick that code should be a minimum of lines. So please suggest me a good solution.
if (userRole.code === ROLE.REFERRINGPROVIDER) {
query = await referralUser(tabCode, userId, query);
} else if (userRole.code === ROLE.CONSULTINGPROVIDER) {
query = await consultingUser(tabCode, userId, query);
} else if (userRole.code === ROLE.PARENT) {
query = await parentUser(tabCode, userId, query);
} else if (userRole.code === ROLE.PHYSICIAN) {
query = await physicianUser(tabCode, userId, query);
}
As shown in the above example I have to write that code for different users, so I have to make it a simple one-line function.