favorite.js 1.86 KB
/**
 * 收藏商品、品牌
 * @type {Object}
 */
'use strict';
const favModel = require('../models/favorite');

const fav = {
    favorite: (req, res) => {
        if (req.query.tab === 'article') {
            res.render('favorite-article', {
                module: 'me',
                page: 'favorite-article'
            });
        } else if (req.query.tab === 'brand') {
            res.render('favorite-brand', {
                module: 'me',
                page: 'favorite-brand'
            });
        } else {
            res.render('favorite', {
                module: 'me',
                page: 'favorite'
            });
        }
    },
    favpaging: (req, res, next) => {
        const uid = req.user.uid;
        const tab = req.query.tab;
        const page = req.query.page;
        const udid = req.sessionID;

        if (tab === 'article') {
            favModel.getFavArticleData(uid, udid, page, 10).then(data => {
                return res.json(data);
            }).catch(next);
        } else if (tab === 'brand') {
            const gender = '1,2,3';

            favModel.getFavBrandData(uid, gender, page, 10).then(data => {
                return res.json(data);
            }).catch(next);
        } else {
            favModel.getFavProductData(uid, page, 10).then(data => {
                return res.json(data);
            }).catch(next);
        }
    },
    deletefav: (req, res, next) => {
        const uid = req.user.uid;
        const favId = req.body.favId;
        const type = req.body.type;

        if (type === 'article') {
            favModel.favArticleDelete(uid, favId).then(data => {
                return res.json(data);
            }).catch(next);
        } else {
            favModel.favoriteDelete(uid, favId, type).then(data => {
                return res.json(data);
            }).catch(next);
        }
    }
};

module.exports = fav;