import {GoodsFavourites, sequelize} from "../../models/index";
import {roles} from "../../utils/constans/signUp";
import forbiddenError from "../../utils/customErrors/forbiddenError";


module.exports = (req, res, next) => {
    if(req.body.role == roles.USER) {
        GoodsFavourites.create({
            userId: req.body.id,
            goodsId: req.params.id
        }).then(() => {
             next();
        }).catch((err) => {
            next(err);
        });
    }else {
        next(new forbiddenError());
    }
};