import {GoodsFavourites} from "../../models/index";


module.exports = async (req, res, next) => {
    const favouriteGoodsUserArray = [];
    const favouriteGoods = await GoodsFavourites.findAll({
        where: {
            userId: req.body.id
        },
        attributes: ['goodsId']
    });

    if(favouriteGoods) {
        favouriteGoods.map(elem => {
           favouriteGoodsUserArray.push(elem.goodsId);
        });
    }

    req.body.favouriteGoodsUserArray = favouriteGoodsUserArray;
    next();
};