text: const router = require("express").Router();
  const User = require("../models");
  const bcrypt = require('bcryptjs');
  
  // Create user
  router.post("/signup", (req, res) => {
      // check whether user exist
      User.findOne({ email: req.body.email })
          .then(user => {
              if (user) {
                  return res.status(400).json({ email: 'Email already exist' })
              } else {
                  if (req.body.profileImg === "") {
                      req.body.profileImg = "https://images-na.ssl-images-amazon.com/images/I/31L9QulMWnL.jpg";
                  };
                  const newUser = new User({
                      firstName: req.body.firstName,
                      lastName: req.body.lastName,
                      email: req.body.email,
                      password: req.body.password,
                      profileImg: req.body.profileImg
                  });
  
                  bcrypt.genSalt(10, (err, salt) => {
                      bcrypt.hash(newUser.password, salt, (err, hash) => {
                          if (err) {
                              res.status(500)
                                  .send(err);
                          };
                          newUser.password = hash;
                          // save user with hashed password
                          newUser
                              .save()
                              .then(user => res.json(user))
                              .catch(err => console.log(err));
                      })
                  })
              }
          });
  });
  
  // Get all users
  router.get("/get", (req, res) => {
      User.find({
          attributes: { exclude: ['password'] },
      })
          .then((dbUserData) => res.json(dbUserData))
          .catch((err) => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  // Get single user
  router.get("/:id", (req, res) => {
      User.findOne({
          attributes: { exclude: ['password'] },
          where: { id: req.params.id },
      })
          .then((dbUserData) => {
              if (!dbUserData) {
                  res.status(404).json({ message: "No user found with this id" });
                  return;
              }
              res.json(dbUserData);
          })
          .catch((err) => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  // Update user
  router.put("/edit/:id", (req, res) => {
      User.update(req.body, {
          individualHooks: true,
          where: {
              id: req.params.id,
          },
      })
          .then((dbUserData) => {
              if (!dbUserData[0]) {
                  res.status(404).json({ message: "No user found with this id" });
                  return;
              }
              res.json(dbUserData);
          })
          .catch((err) => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  // Delete user
  router.delete("/delete/:id", (req, res) => {
      User.destroy({
          where: {
              id: req.params.id,
          },
      })
          .then((dbUserData) => {
              if (!dbUserData) {
                  res.status(404).json({ message: "No user found with this id" });
                  return;
              }
              res.json(dbUserData);
          })
          .catch((err) => {
              console.log(err);
              res.status(500).json(err);
          });
  });
  
  module.exports = router;
  