...
|
...
|
@@ -10,13 +10,44 @@ const _ = require('lodash'); |
|
|
const url = require('url');
|
|
|
|
|
|
const findBySkn = (skn) => {
|
|
|
return api.getProductAsync(skn).then((result) => {
|
|
|
return {
|
|
|
url: url.parse(_.get(result, 'data.product_url', '')).path
|
|
|
};
|
|
|
return api.getProductBySknAsync(skn).then((result) => {
|
|
|
if (result.code === 200 && result.data.product_url) {
|
|
|
return {
|
|
|
url: url.parse(_.get(result, 'data.product_url', '')).path
|
|
|
};
|
|
|
} else {
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const findBySku = (sku) => {
|
|
|
return api.getProductBySkuAsync(`[${sku}]`).then((result) => {
|
|
|
if (result.code === 200 && !_.isEmpty(result.data)) {
|
|
|
let product = _.head(result.data) || {};
|
|
|
let skn = product.erpProductId || '';
|
|
|
|
|
|
if (skn) {
|
|
|
return findBySkn(skn);
|
|
|
}
|
|
|
|
|
|
return {};
|
|
|
} else {
|
|
|
return {};
|
|
|
}
|
|
|
});
|
|
|
};
|
|
|
|
|
|
const find = (q) => {
|
|
|
if (q.sku) {
|
|
|
return findBySku(q.sku);
|
|
|
} else if (q.skn) {
|
|
|
return findBySkn(q.skn);
|
|
|
} else {
|
|
|
return Promise.reject();
|
|
|
}
|
|
|
};
|
|
|
|
|
|
module.exports = {
|
|
|
findBySkn
|
|
|
find
|
|
|
}; |
...
|
...
|
|