My problem is the following: I need to register 2 kinds of users (student and teacher), but the user controller is unique (there are just some optional values that I check on the controller according to the user form). What are my options to control what form should I render based on the request url ( or sending a variable from the route, for example).
Code below:
- newStudent and newTeacher are also my ejs CRUD files, so I just omitted them.
Routes
router.get('/newStudent', user_controller.user_create_get);
router.post('/newStudent', user_controller.user_create_post);
router.get('/newTeacher', user_controller.user_create_get);
router.post('/newTeacher', user_controller.user_create_post);
Controller
exports.user_create_get = function(req, res) {
// here I would like to place an if to render newStudent or newTeacher
// according to the route path request
res.render('newStudent');
res.render('newTeacher');
}
Any advices are welcome. Also, should I build different controllers? Even if the register form is similar ?