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

module.exports = (req, res, next) => {
    const newUser = Object.assign(req.body, {role: roles.USER});

    Users.create(newUser)
        .then(result => {
            req.body.id = result.dataValues.id;
            next();

        }).catch(() => {
        next(new signUpCreateUserError());
    });
};