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

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