search.js 982 Bytes
const _ = require('lodash');
const api = global.yoho.API;
const camelCase = global.yoho.camelCase;
const prettyFilter = require(`${global.utils}/beautify/filters`);
const processProductList = require(`${global.utils}/beautify/product`);

const search = {
    products(params) {
        if (params.hasOwnProperty('priceRange')) {
            params.price = params.priceRange;
            delete params.priceRange;
        }

        const data = _.merge({
            method: 'app.search.li'
        }, params);

        return api.get('', data, {
            cache: true,
            code: 200
        }).then(result => {
            result = result || {};
            if (result.data) {
                prettyFilter(result.data.filter);
                result = camelCase(result);
                result.data.productList = processProductList(result.data.productList, {gender: params.gender});
            }
            return result;
        });
    }
};

module.exports = search;