channel.js 1.53 KB
'use strict';
const service = global.yoho.ServiceAPI;
const api = global.yoho.API;
const processResources = require(`${global.utils}/beautify/resources`);
const processProductList = require(`${global.utils}/beautify/product`);

let channel = {
    getResourcesData(params) {
        if (!params.contentCode) {
            return Promise.resolve([]);
        }
        return service.get('operations/api/v5/resource/get', {
            content_code: params.contentCode
        }, {
            cache: true,
            code: 200
        }).then(result => {
            return result && result.data ? processResources(result.data) : [];
        });
    },
    getSidebarData() {
        return service.get('operations/api/v6/category/getCategory', {
            parent_id: 1155
        }, {
            cache: true,
            code: 200
        }).then(global.yoho.camelCase);
    },
    getGoodsData(params) {
        if (!params.productSkn || !params.productSkn.length) {
            return Promise.resolve([]);
        }
        return api.get('', {
            method: 'h5.product.batch',
            productSkn: params.productSkn
        }, {
            cache: true,
            code: 200
        }).then(result => {
            return result && result.data ? processProductList(result.data.product_list) : [];
        });
    },
    getChannelData() {
        return api.get('', {
            method: 'app.blk.getAllChannels'
        }, {
            cache: true,
            code: 200
        }).then(global.yoho.camelCase);
    }
};

module.exports = channel;