common.js 1015 Bytes
/**
 * common model
 * @author: yyq<yanqing.yang@yoho.cn>
 * @date: 2016/08/03
 */
'use strict';

const _ = require('lodash');

const serviceApi = global.yoho.ServiceAPI;
const helpers = global.yoho.helpers;

/**
 * 获取资源数据api
 * @function _getResourceData
 * @param { string } code 资源码
 * @return object
 */
const _getResourceDataAsync = (code) => {
    return serviceApi.get('operations/api/v5/resource/get', {
        content_code: code
    }, {code: 200});
};

const getBannerData = (code) => {
    return _getResourceDataAsync(code).then(result => {
        let resData = {
            code: 404,
            message: '获取资源信息失败'
        };

        if (!_.isEmpty(result.data)) {
            resData = Object.assign({code: 200}, result.data[0]);
            if (resData.data && resData.data.src) {
                resData.data.src = helpers.image(resData.data.src, 330, 390);
            }
        }

        return resData;
    });
};

module.exports = {
    getBannerData
};