Step 17: Update users route

Let's update src/routes/users.js to account for the updates made to UserDao.

  • Update the get request handler:

    router.get(`${endpoint}`, async (req, res, next) => {
      debug(`${req.method} ${req.path} called...`);
      try {
        const { name, email, role } = req.query;
        const users = await userDao.readAll({ name, email, role });
    
  • Update the post request handler:

    router.post(`${endpoint}`, async (req, res, next) => {
      debug(`${req.method} ${req.path} called...`);
      try {
        const { name, email, password, role } = req.body;
        const user = await userDao.create({ name, email, password, role });
    
  • Update the put request handler:

    router.put(`${endpoint}/:id`, async (req, res, next) => {
      debug(`${req.method} ${req.path} called...`);
      try {
        const { id } = req.params;
        const { name, email, password, role } = req.body;
        const user = await userDao.update({ id, name, email, password, role });
    

Refer to the commit history to see the changes made at this step.