var express = require('express')
const router = express.Router();
const db = require("../../utils/database");
const bcrypt = require('bcrypt');


router.post('/updatePassword',(req,res)=>{
    const userId = req.body.userId;
    const newPassword = req.body.newPass;
    bcrypt.hash(newPassword, 14, function (err, hash) {
        if (err) {
            console.log(err);
            return res.json({
                message: "Error while hashing",
                error: err
            })
        }
        else{
            let query= `UPDATE finehhdi_fineAD.users set password = '${hash}' where id = ${userId} `
            db.query(query,(err,data)=>{
                if(err){console.log(err)}
                else{
                    res.status(200).send({
                        message:'Successfully Updated'
                    })
                }
            })
        }
    
})
})
module.exports = router;