import {roles} from "../../utils/constans/signUp";
import forbiddenError from "../../utils/customErrors/forbiddenError";
import {Users} from "../../models";
import userNotFound from "../../utils/customErrors/userNotFound";

module.exports = async (req, res, next) => {

    if(req.body.role == roles.ADMIN) {
        next(new forbiddenError());
    }else {
        const user = await Users.findOne({
            where: {
                id: req.body.id
            }
        });


        if(!user) {
            next(new userNotFound());
        }else {
            user.update(req.body);
            next();
        }
    }
}