var express = require("express");
const router = express.Router();
const db = require("../../utils/database");
const dbFuntion = require("../../utils/dbfunction");
const bcrypt = require("bcrypt");
const { response } = require("express");
var jwt = require("jsonwebtoken");
const { json } = require("body-parser");

router.get('/getUsers',(req,res)=>{
  getUsersQuer=`Select * From finehhdi_fineAD.users`
  let objData = []
  db.query( getUsersQuer,(err,data)=>{
    if(err){
      console.log(err)
      res.json({err,error:"Users Not Found"})
    }
    else{
     data.map(item=>{
   const {password, ...other} = item
   objData.push(other)
     })
    res.status(201).json(objData)
    }
  })
 
})

router.get("/selectUser", (req, res) => {
  var username = req.body.username;
  //   console.log(email, password);

  db.query(
    `select isAdmin from finehhdi_eDefect.users where username="${username}"`,
    (err1, data) => {
      if (err1) {
        console.log(err1);
        res.json({
          error: err1,
        });
      } else {
        console.log("get request success");
        res.status(201).json({
          data: data,
        });
      }
    }
  );
});
module.exports = router;
