const bcrypt = require('bcrypt');
import uncorrectPassword from '../../utils/customErrors/uncorrectPassword';

module.exports = (req, res, next) => {
    if(req.body.rightPassword) {

        bcrypt.compare(req.body.oldPassword ? req.body.oldPassword : req.body.password,
            req.body.rightPassword, (err, result) => {

                if(!result) {
                    next(new uncorrectPassword());
                }else {
                    next();
                }

        });
    }else {
        next();
    }
};