Authored by htoooth

refactor

... ... @@ -20,9 +20,10 @@ const index = (req, res, next)=> {
let sort = req.query.sort_id || 0;
let reduction = req.query.is_reduction || 'N';
let promotion = req.query.is_promotion || 'N';
let limit = 10, data = {};
let limit = 10;
let data = {};
data.tabs = favoriteService.getFavoriteTabs(type);
data.tabs = favoriteService.getFavoriteTabs('product');
switch (type) {
case 'brand':
... ... @@ -30,7 +31,7 @@ const index = (req, res, next)=> {
break;
case 'article':
data.favArticles = yield favoriteService.favoriteArticleList(uid, udid, page, limit, type);
data.favArticles = yield favoriteService.favoriteArticleListAsync(uid, udid, page, limit);
break;
default:
... ... @@ -48,8 +49,8 @@ const index = (req, res, next)=> {
const reductionAction = ()=> {
}
};
module.exports = {
index
}
};
... ...
... ... @@ -20,9 +20,7 @@ const getFavoriteTabs = (type) => {
type = type || 'product';
return TABS.map((item) => {
if (item.type === type) {
item.active = true;
}
item.active = item.type === type;
item.url = helpers.urlFormat('/home/favorite', {type: item.type});
return item;
});
... ... @@ -149,13 +147,13 @@ const favoriteBrandList = (uid, page, limit, type)=> {
})();
};
const favoriteArticleList = (uid, udid, page, limit, type)=> {
const favoriteArticleListAsync = (uid, udid, page, limit)=> {
return co(function*() {
let result = {articles: [], pager: {}};
let article = yield favoriteApi.favoriteArticleData(uid, udid, page, limit);
let articles = yield favoriteApi.favoriteArticleData(uid, udid, page, limit);
if (!article.data && !article.data.data) {
article.data.data.forEach((item, i)=> {
if (!articles.data && !articles.data.data) {
articles.data.data.forEach((item)=> {
result.articles.push({
id: item.id,
name: item.title,
... ... @@ -165,11 +163,11 @@ const favoriteArticleList = (uid, udid, page, limit, type)=> {
});
});
let total = article.data.total || 0;
let pageTotal = article.data.totalPage || 0;
let page = article.data.page || 0;
let total = articles.data.total || 0;
let pageTotal = articles.data.totalPage || 0;
let pageNum = articles.data.page || 0;
result.pager = getPager(page, total, pageTotal);
result.pager = getPager(pageNum, total, pageTotal);
} else {
result.articles = {empty: '你尚未收藏任何文章!'};
}
... ... @@ -261,5 +259,5 @@ const getSortInfo = (categoryList, sort)=> {
module.exports = {
getFavoriteTabs,
favoriteProductList,
favoriteArticleList
favoriteArticleListAsync
};
... ...
... ... @@ -165,6 +165,7 @@ router.get('/vip', VipController.index);
router.get('/favorite', FavoriteController.index);
router.get('/coupons', CouponsController.index);
module.exports = router;
... ...
'use strict';
let Promise = require('bluebird');
let co = Promise.coroutine;
co(function*() {
let a = yield Promise.reject(3);
console.log('here');
a = 4;
return a;
})().then(a=>console.log(a))
.catch(a=>console.log(a));