search.js
1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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);
delete data.client_type;
delete data.client_secret;
return api.post('', data, {
cache: true,
code: 200
})
.then(result => {
if (!result.hasOwnProperty('code')) {
result.code = 200;
}
if (result.code === 200) {
prettyFilter(result.data.filter);
result.data.productList = processProductList(result.data.productList);
result = camelCase(result);
}
return result;
});
}
};
module.exports = search;