favorite.js 1.46 KB
/**
* 个人中心我的收藏
* @author: zxr<xiaoru.zhang@yoho.cn>
* @date: 2016/08/16
*/

'use strict';

const favoriteModel = require('../models/favorite');

const favorite = (req, res) => {

    // favoriteModel.getfavoriteData(uid, page, limit).then((result) => {

    // }).catch(next);
    res.render('favorite', {
        module: 'home',
        page: 'favorite',
        favorite: {
            productUrl: 'm.yohobuy.com',
            brandUrl: 'm.yohobuy.com'
        }
    });
};

let favProduct = (req, res, next) => {
    let uid = req.user.uid;
    let page = req.query.page || 1;
    let limit = 10;

    favoriteModel.favProduct(uid, page, limit).then((result) => {
        res.render('favorite/favorite-product', {
            layout: false,
            hasFavProduct: result
        });
    }).catch(next);
};

let favfavBrand = (req, res, next) => {
    let uid = req.user.uid;
    let page = req.query.page || 1;
    let limit = 10;

    favoriteModel.favfavBrand(uid, page, limit).then((result) => {
        res.render('favorite/favorite-brand', {
            layout: false,
            hasFavBrand: result
        });
    }).catch(next);
};

let favoriteDelete = (req, res, next) => {
    let uid = req.user.uid;
    let type = 'product';
    let favId = req.body.id;

    favoriteModel.favoriteDelete(uid, type, favId).then((result) => {
        res.json(result);
    }).catch(next);
};

module.exports = {
    favorite,
    favProduct,
    favfavBrand,
    favoriteDelete
};