channel.js 1.84 KB
'use strict';

const service = global.yoho.ServiceAPI;
const processResources = require(`${global.utils}/beautify/resources`);
const processProductList = require(`${global.utils}/beautify/product`);


let channel = class extends global.yoho.BaseModel {
    constructor(ctx) {
        super(ctx);
    }

    getResourcesData(params) {
        if (!params.contentCode) {
            return Promise.resolve([]);
        }

        return this.get({
            api: service,
            url: 'operations/api/v5/resource/get',
            data: {
                content_code: params.contentCode
            },
            param: {
                cache: true,
                code: 200
            }
        }).then(result => {
            return result && result.data ? processResources(result.data) : [];
        });
    }

    getSidebarData() {
        return this.get({
            api: service,
            url: 'operations/api/v6/category/getCategory',
            data: {},
            param: {
                cache: true,
                code: 200
            }
        });
    }

    getGoodsData(params) {
        if (!params.productSkn || !params.productSkn.length) {
            return Promise.resolve([]);
        }

        return this.get({
            data: {
                productSkn: params.productSkn,
                method: 'h5.product.batch'
            },
            param: {
                cache: true,
                code: 200
            }
        }).then(result => {
            return result && result.data ? processProductList(result.data.product_list) : [];
        });
    }

    getChannelData() {
        return this.get({
            data: {
                method: 'app.blk.getAllChannels'
            },
            param: {
                cache: true,
                code: 200
            }
        });
    }
};

module.exports = channel;