i have a class for hash data in nodejs .
this is my class :
const bycrypt = require("bcrypt");
module.exports = new (class Utilitie {
HashField(field) {
return new Promise((resolve, reject) => {
bycrypt.hash(field, bycrypt.genSaltSync(15), (error, hash) => {
if (error) return reject(error);
resolve(hash);
});
});
}
})();
and this is my controller for use this class for hash data :
async ResetPassword(req, res, next) {
const result = await this.ValidationAction(req, res);
if (result[0]) {
let user = await User.findOne({ userName: req.body.userName }).then(
(user) => {
if (!user) return this.Notfound(res);
user.password = Utilite.HashField(req.body.password).then(
(error, hash) => {
console.log("in controller", hash);
}
);
user.save();
}
);
this.Ok(res);
}
return this.BadRerquest(res, result[1]);
}
but it not hash field and it return the undefined
.
whats the problem ? how can i solve this problem ????