detail-comment-service.js 1.22 KB
/**
 * Created by TaoHuang on 2016/6/14.
 */

'use strict';

const Promise = require('bluebird');
const co = Promise.coroutine;
const _ = require('lodash');

const helpers = global.yoho.helpers;
const api = require('./detail-comment-api');
const detailHelper = require('./detail-helper');


const indexAsync = (pid, page, size) => {
    return co(function *() {
        let commentList = yield api.indexAsync(pid, page, size);

        if (!(commentList.code && commentList.code === 200)) {
            return [];
        }

        return commentList.data.map(value => {
            let item = {};

            let avatar = detailHelper.DEFAULT_AVATAR_ICO;

            if (value.head_ico) {
                avatar = `${detailHelper.IMAGE_SERVICE_URL}${_.last(value.head_ico.split('headimg'))}`;
                avatar = helpers.image(avatar, 30, 30);
            }

            item.avatar = avatar;
            item.userName = value.nickname;
            item.color = value.color_name;
            item.size = value.size_name;
            item.comment = value.content || '';
            item.date = value.create_time;
            item.total = value.total;

            return item;
        });

    })();
};

module.exports = {
    indexAsync
};