const app = require('express')
const router  = app.Router();
const db = require("../config/conn")
const bcrypt = require('bcrypt');

router.post('/', async(req, res)=>{
    const {name, email, password} = req.body
        const hashedPassword = await bcrypt.hash(password, 10);
        const insertUser = "INSERT INTO user(name, email, password) VALUES(?,?,?)";
    
        db.query(insertUser, [name, email, hashedPassword], (err, result)=>{
            if(err) {
                console.log('Failed to insert into user table')
            }
        })
        res.send('<script>alert("Successfully Added"); window.location.href=".././admin/signup"</script>');
})

module.exports = router;