text: import { Router } from "express";
  import UserService from "../../service/UserService";
  import { check, validationResult } from "express-validator";
  
  const router = Router();
  
  router.post(
    "/signup",
    [
      check("name", "Name is Required").notEmpty(),
      check("email", "Please include a valid email").isEmail(),
      check("password", "Please Enter password with 6 or more").isLength({
        min: 6,
      }),
    ],
    (req, res) => {
      const errors = validationResult(req);
      if (!errors.isEmpty()) {
        return res.status(400).send(errors.array()[0].msg);
      }
      console.log(req.body);
      const { name, email, password } = req.body;
      UserService.signUp({ name, email, password })
        .then((user) => {
          console.log("User signup:", user);
          const payload = { userId: user._id, isAdmin: user.isAdmin };
          res.status(200).json(payload);
        })
        .catch((err) => {
          console.log(err);
          res.status(401).send(err);
        });
    }
  );
  
  router.post(
    "/login",
    [
      check("email", "Please include a valid email").isEmail(),
      check("password", "Password is required").exists(),
    ],
    (req, res) => {
      const errors = validationResult(req);
      if (!errors.isEmpty()) {
        return res.status(400).send(errors.array()[0].msg);
      }
      console.log(req.body);
      const { email, password } = req.body;
      UserService.logIn({ email, password })
        .then((user) => {
          console.log("User login:", user);
          const payload = { userId: user._id, isAdmin: user.isAdmin };
          res.status(200).json(payload);
        })
        .catch((err) => {
          console.log(err);
          res.status(401).send(err);
        });
    }
  );
  
  export default router;
  